I would like to exit from a script if a function fails. Normally this is not a problem, but it becomes a problem if you use process substituion.
$ cat test.sh
#!/bin/bash
foo(){
[ "$1" ] && echo pass || exit
}
read < <(foo 123)
read < <(foo)
echo 'SHOULD NOT SEE THIS'
$ ./test.sh
SHOULD NOT SEE THIS
Based on CodeGnome’s answer this seems to work
$ cat test.sh
#!/bin/bash
foo(){
[ "$1" ] && echo pass || exit
}
read < <(foo 123) || exit
echo 'SHOULD SEE THIS'
read < <(foo) || exit
echo 'SHOULD NOT SEE THIS'
$ ./test.sh
SHOULD SEE THIS
{ test -n "$1" && echo pass; } || exit 1instead.