#!/bin/sh
date;
perl aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.pl
date;
The script does not exist and it should fail.
Exit status (0 is success, everything else is failure) of script is exit status of last command. To fix, store the right exit status in shell variable before doing something else. Example:
#!/bin/sh
date
perl aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.pl
perlexitstatus=$?
date
exit $perlexitstatus
For completeness, two other ways:
#!/bin/sh
set -e # exit on non-zero command exitcode
date
perl aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.pl
date
Above is often a bit inconvenient, because often shell script has commands you don't care about, and don't want the script to fail for them.
#!/bin/sh
set -e # exit on non-zero command exitcode
date
perl aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.pl ||
{ echo "aaaa... Script failed, spam [email protected]"; exit 1;}
date
Last one could be written with if-then-fi statement too, if preferred. It provides a way to print custom error message, in case the failing command's message is unclear.
If you set shebang with a shell you could provide -e parameter to make script break on inner command failures:
#!/bin/sh -e
date;
perl aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.pl
date;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With