0

This script shell works fine on GNU/Linux but not on AIX 5.3

#!/bin/sh

echo $SHELL

set -o nounset -o errexit

[ 1 -eq 1 ] && {
  echo "zzz"
} && echo "aaa" && [ 1 -eq 0 ] && echo "bbb"
echo "ccc"

On GNU/Linux, I've got the expected output :

/bin/bash
zzz
aaa
ccc

On AIX, I've got this one :

/bin/ksh
zzz
aaa

Without "set -o nounset -o errexit" it works fine... I don't understant why. Could you explain me what is wrong in my script shell.

Thanks,

Rémy


Edit 18 nov. : Precision

set -e When this option is on, if a simple command fails for any of the reasons listed in Consequences of Shell Errors or returns an exit status value >0, and is not part of the compound list following a while, until, or if keyword, and is not a part of an AND or OR list, and is not a pipeline preceded by the ! reserved word, then the shell shall immediately exit. http://explainshell.com/explain?cmd=set+-e

In my example, the second test "[ 1 -eq 0 ]" is part of an AND, so I should see the output "ccc". This test returns 1, it traps the output "bbb", but should'nt exit the script.

Rémy

Rémy J.
  • 21
  • 2
  • I guess `/bin/sh` in your Linux (probably `ash` or `dash`) simply doesn't understand `set -o errexit`. Use bash (let the first line be `#!/bin/bash`) Edit: env `SHELL` being `/bin/bash` doesn't prove anything, don't rely on it. – Zsigmond Lőrinczy Nov 17 '16 at 19:51

1 Answers1

0

Have the same behavior on AIX 6 and 7

Rémy

Rémy J.
  • 21
  • 2