>>Another example is "select".  If you do something like:

>>$ set -e
>>$ select var in one two three; do echo "var = $var"; done
>>$

>>And then hit ^D at the "#?" prompt, it will exit the "select"
>>statement with status 1 but will *not* abort the shell.  So, you need
>>to append "|| exit" after the "done", to get that behavior.  Again,
>>I'm sure there is a reason for this, but I remain unconvinced.

>Korn shell compatibility, since ksh is where select originated.

Actually, as I understand it, this affects all so-called "compound commands"
(I hope I am using the terminology correctly) - not just "select".

Observe:

 $ trap
trap -- 'echo "Status: $?"' ERR
 $ ls ksjdfh
ls: cannot access 'ksjdfh': No such file or directory
Status: 2
 $ case 1 in 1) ls ksjdfh && :; esac
ls: cannot access 'ksjdfh': No such file or directory
 $ echo $?
2
 $ case 1 in 1) ls ksjdfh && :; esac || echo Fail
ls: cannot access 'ksjdfh': No such file or directory
Fail
$

The point is that "case" retains the exit status of the last executed
command (the failed "ls"), but does not itself trigger the trap.

As with the "select" example, one needs to explicitly append
"|| echo Fail", in order to act upon the exit status of the "case"
construct.


  • "set -e&quo... Stan Marsh
    • Re: "s... Lawrence Velázquez
    • Re: "s... Duncan Roe via Bug reports for the GNU Bourne Again SHell
      • Re: &qu... Lawrence Velázquez
        • Sou... Duncan Roe via Bug reports for the GNU Bourne Again SHell

Reply via email to