Is it possible to exit a script from a function that is called using command substitution?
e.g
#/bin/bash
function do_and_check()
{
ls $1 || exit
}
p=$(do_and_check /etc/passwd)
q=$(do_and_check /xxx)
the result of running this is
bash -x yyy
++ do_and_check /etc/passwd
++ ls /etc/passwd
+ p=/etc/passwd
++ do_and_check /xxx
++ ls /xxx
ls: cannot access /xxx: No such file or directory
++ exit
+ q=
+ echo /etc/passwd
/etc/passwd
I would have liked the exit to take me out of the script, not out of the command substitution. Is that possible?