[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Bash4: Problem retrieving "$?" when running with "-e"
From: |
Lenga, Yair |
Subject: |
Bash4: Problem retrieving "$?" when running with "-e" |
Date: |
Fri, 12 Apr 2013 11:44:49 +0000 |
Good Morning,
I've encountered another interesting change in behavior between Bash3 and
Bash4. I hope that you can help me:
The core question is how to retrieve the status of a command, when running with
'-e'
For production critical jobs, we run the script in '-e', to ensure that all
steps are successful. For cases where we allow the command to fail, because we
can implement backup, we add explicit error handing. For example.
set -ue
CHECK_SPACE
(FETCH_NEW_DATA)
If [ $? = 11 ] ; then
FETCH_BACKUP_DATA
fi
REMOVE_OLD_DATA
COPY_NEW_TO_OLD
In Bash3, the script could retrieve the return code for FETCH_NEW_DATA, by
placing it into a sub-shell, and then examining the value of "$?".
In Bash4, the FETCH_NEW_COMMAND failure cause the parent script to fail.
The man page says that '-e' will "exit immediately if a simple command (note
Simple Command::) exits with non-zero status unless ...".
The "simple commands" definition is a "sequence of words separate by blanks
...". According to this definition, the sequence "( simple command )"
Is NOT a simple command, and should NOT trigger the "immediate exit".
Can anyone comment on my interpretation. Is there alternative solution that
will allow retrieval of the status of single commands when running
With the '-e' ?
Thanks
Yair Lenga
- Bash4: Problem retrieving "$?" when running with "-e",
Lenga, Yair <=