getinfo.sh which either prints information or exists with code 1.
I want to store the result of this script in a bash variable, otherwise print an error message and exit.
If I run this
#!/bin/bash X=`getinfo.sh` || echo "failed" && exit 1
then the script exits even when
getinfo.sh succeeds (in this case it prints nothing.
On the other hand
X=`getinfo.sh` || (echo "failed" && exit 1)
which makes sense to me, coming from C-like languages, but this does not exit the script since the parentheses create a new, inner shell, and it is the inner-shell which is exited, the outer shell keeps running.
How can I store the output of
getinfo.sh and print-and-exit if that fails?