I have been reading about bash set -e
option, and still a bit confused on why the below pipe continues to execute when the file test-output.xml
does not exist.
Is setting set -e
only applicable to the exit status of the last command? I can't find this statement (well, explicitly) in the documentation(s) for this option (e.g. tldp.org -> bash options).
Thank you for all your help!
#!/usr/local/bin/bash
set -e
fail_tests=`cat test-output.xml|grep '^<testng-results '|perl -e 'print "0";'`
echo $?
echo "fail_tests: [$fail_tests]"
outputs:
cat: test-output.xml: No such file or directory
0
fail_tests: [0]
However, if I change the command to:
#!/usr/local/bin/bash
set -e
fail_tests=`cat test-output.xml|grep '^<testng-results '|perl -e 'print "0"; exit 1;'`
echo $?
echo "fail_tests: [$fail_tests]"
it outputs:
cat: test-output.xml: No such file or directory
running with bash version:
➜ ~ /usr/local/bin/bash -version
GNU bash, version 5.0.18(1)-release (x86_64-apple-darwin19.5.0)
Copyright (C) 2019 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software; you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.