Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Unexpected behavior with “set -o errexit” on AIX

Status
Not open for further replies.

RemyJ

Programmer
Nov 24, 2016
1
FR
This script shell works fine on GNU/Linux but not on AIX 5.3 and later :

Code:
#!/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.

man ksh :
-e
Executes the ERR trap, if set, and exits if a command has a nonzero exit status, unless in the following conditions:
* The simple command is contained in a "&&" or "||" list.
* The simple command immediately follows "if", "while" or "until".
* The simple command is contained in a pipeline following "!".
This mode is disabled when profiles are read.

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.

Thanks

Rémy
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top