On Mon, Jul 2, 2012 at 4:19 PM, Janis Papanagnou <
[email protected]> wrote:

>
> If you are speaking of a problem it would be helpful if you'd exactly
> specify
> the conditions you expect; and why. A reference to bash behaviour seems not
> to be an appropriate measure.
>

You're right. It's always a challenge for me to make myself understood
right in English. I mentioned Bash here just to help others understand my
problem.

>
> The question is, what do you expect as a possible range of exit codes, and
> in what way do you want to do the signalling of exit codes and/or signals.
>
> If, in your applications context, you don't have exit codes >128 then just
> subtract 128, as in
>     (( rc >= 128 )) && (( rc -= 128 ))
>     return $rc
> but then you wouldn't be able to distinguish signals from exit status.
>
> My purpose is to pass the $? value (unchanged) from the wrapper function
"runcmd" to its caller so the caller can tell if the command exited
normally or it was killed by a signal.

>
> ________________________________
> > From: [email protected]
> > Date: Mon, 2 Jul 2012 11:01:59 +0800
> > Subject: [ast-users] [ksh93] How to return $? from a function when $? >
> 256
> > To: [email protected]; [email protected]
> > CC:
> >
> > For example, following code is very common in scripts:
> >
> > ### CODE BEGIN ###
> > function debug
> > {
> >      return
> > }
> >
> > function runcmd
> > {
> >      typeset cmd=$1
> >      typeset rc
> >
> >      debug "+++ $cmd"
> >      eval "$cmd"
> >      rc=$?
> >      if (( rc )); then
> >          debug "+++ $cmd failed with $rc"
> >      else
> >          debug "+++ $cmd succeeded"
> >      fi
> >
> >      return $rc
> > }
> >
> > runcmd '/usr/bin/sleep 15'
> > echo $?
> > ### CODE END ###
> >
> > The problem is when the command is killed by a signal, we cannot return
> > the correct $? (> 256) from the runcmd() function. Bash does not has
> > this problem since $? is equal to 128+signal when a command is killed.
> >
> > _______________________________________________ ast-users mailing list
> > [email protected]
> > https://mailman.research.att.com/mailman/listinfo/ast-users
>
_______________________________________________
ast-users mailing list
[email protected]
https://mailman.research.att.com/mailman/listinfo/ast-users

Reply via email to