lundi 30 mars 2020

why bash does not exit on test syntax error?

I would like a script to exit on a syntax error occurring on a test, but no luck :

bash -n "$0" || exit  # check script syntax

#set -xv
set -o nounset
set -o errexit
set -o pipefail # make pipes fail if one of the piped commands fails

if (( != 0 )); then  # syntax error here
  echo "after if"
fi

echo "should not reach this point, but indeed does"

output is :

./testscript: line 8: ((: != 0 : syntax error: operand expected (error token is "!= 0 ")
should not reach this point, but indeed does

any solution ? thanks

Aucun commentaire:

Enregistrer un commentaire