INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

Jobs from Indeed

Unexpected behavior with “set -o errexit” on AIX

Unexpected behavior with “set -o errexit” on AIX

(OP)
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 :

Quote:

/bin/bash
zzz
aaa
ccc

On AIX, I've got this one :

Quote:

/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 :

Quote:

-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

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close