bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Bash4: Problem retrieving "$?" when running with "-e"


From: John Kearney
Subject: Re: Bash4: Problem retrieving "$?" when running with "-e"
Date: Fri, 12 Apr 2013 16:36:13 +0200
User-agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:17.0) Gecko/20130328 Thunderbird/17.0.5

Am 12.04.2013 13:44, schrieb Lenga, Yair:
> 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
>
>
>
>
try this approach

set -ue
CHECK_SPACE
RVAUE=0
 (FETCH_NEW_DATA) || RVALUE=$?
If [ $RVALUE  = 11 ] ; then
        FETCH_BACKUP_DATA
fi
REMOVE_OLD_DATA
COPY_NEW_TO_OLD





reply via email to

[Prev in Thread] Current Thread [Next in Thread]