ksh errexit compound commands help

ksh errexit compound commands help

Post by Ian Goodac » Sat, 27 Feb 1993 06:28:13



I am running Intergraph's CLIX 3.1 r.6.5.7 ( an AT&T system V release 3
derivative I believe) on an Intergraph workstation.

I am having unexpected behaviour with a ksh script as follows:

#
# This is a simple subshell command group which invokes the errexit function
#
(
  set -e
  trap "echo exit trap; exit 1" ERR
  (exit 1)
  echo $?
  exit 0
)

#
# The following test should be equivalent to a '||' OR list
#
if [[ $? != 0 ]]
then
  echo failed
fi

#
# In the following case, '||' OR list is used. I expected the result
# to be the same as the sequence above, but it isn't. For some reason,
# on my system the OR list interferes with the 'errexit' (-e) function,
# and the trap is never executed.
#
(
  set -e
  trap "echo exit trap; exit 1" ERR
  (exit 1)
  echo $?
  exit 0
) || echo failed

Intergraph says this works as designed. Their explanation is that the
set -e option failes in the latter case because the subshell command
grouping is a component of a larget compound command (the OR list).

I though the subshell command grouping '(compound-list)' was
functionally equivalent to running compound-list in a subshell, except
that the process number doesn't change, in which case whether it was
part of a larger compound command would be irrelevant.

Can anyone try this on other implementations and let me know what the
results are?

Is Intergraph wrong and this a bug, or have I misunderstood something?

Thanks for any help.

Ian Goodacre

 
 
 

ksh errexit compound commands help

Post by Eric Gis » Wed, 03 Mar 1993 08:06:48


I have simplified you example to make it easier to present:
Here is what the Bourne and Korn shell do:
        (set -e; false || echo False)
        False
        (set -e; false; echo ignored -e!) || echo False!
        ignored -e!
        { set -e; false; echo ignored -e!; } || echo False!
        ignored -e!
The exceptions to -e (-o errexit) has never been documented,
POSIX.2 has specified the first case: the ||, &&, if, and while
statements ignore the -e flag when executing the predicate.
I would guess the implementors never considered the last two cases,
and the results are just side effects of the implementation.

Here is what the MKS shell does
(I'm not saying this is right, we never considered these cases):
        (set -e; false || echo False)
        False
        # we clear the "ignore -e" flag for subshells
        (set -e; false; echo ignored -e!) || echo False!
        False!
        { set -e; false; echo ignored -e!; } || echo False!
        ignored -e!

 
 
 

1. Puzzling ksh behaviour with set -o errexit

  I have found using ksh on AIX 3.2.5 the following puzzling, to me at any
rate, behaviour.  A command line like

        ( set -o errexit; qwert; print x $? ); print z

produces the output (behaviour A)

        ksh: qwert:  not found
        z

while

        ( set -o errexit; qwert; print x $? ) && print z

produces (behaviour B)

        ksh: qwert:  not found
        x 1
        z

Behaviour A seems reasonable from the description I've read of "set -o
errexit" (if a command has a false return value then exit, in this case
from the () sub-shell).  I don't understand why the second command line
produces behaviour B.
  I've tried the same command lines on an Irix 5.2 and they work the same
way as AIX, so I must be be missing something (or they're both doing the
same wrong thing).


            | 494-3332     | University Computing & Information Services
                           | Dalhousie University, Halifax, N.S., Canada

2. Switching screens

3. piping compound commands - need help

4. How to tell if a process is reading from a pipe

5. Q: Compound conditions in ksh

6. Local delivery problems with Qmail

7. How to _repeat_ a compound command in csh/tcsh

8. What's up?

9. ksh: 2 Q's, command completion & command history?

10. HELP: Command-line editing with ksh/csh

11. Help: Is there a structured storage library for Linux (like MS OLE's compound file)?

12. what is the maximum size of command line on KSH ?

13. awk-command in ksh script ?