I have a script test.sh
#/!bin/bash
set -e
trap errorhandler ERR
errorhandler(){
status=$?
trap - ERR
exit $status
}
echo "$@"
exit 0
when I call sh test.sh 'Hey' it will print -e instead of Hey.
My work around is surround set -e with backticks but dont know if it still works as intended
Another workaround is to store it in a variable in the first line but I would like my set -e in the first line for one obvious reason (handling an error).
Is there a clever way to do this? Like “Hey don’t touch my $@” command.
Got it!
-eand–enotice the dash. the first one is correct.Lesson learned. Do not copy code directly from html.