On 12/30/14 7:03 AM, Ville Oikarinen wrote:
> Hello.
> 
> I often use "set -eu" to make my scripts more robust by exiting when
> there are errors.
> 
> But one of my scripts just kept on running after failures. I found out
> that the keyword "local" does not obey it. Here is a script to
> reproduce the problem:

This is not a bug.


> #!/bin/bash
> 
> set -eu
> 
> failure() {
>     echo "going to fail"
>     false
> }
> 
> cmd-subst-failure-with-local() {
>     echo "calling failure without failing because of local"
>     local FAILUREOUT=$(failure)
>     echo "Bug: set -eu wasn't effective: failure output was '$FAILUREOUT'"
> }
> 
> cmd-subst-failure-without-local() {
>     echo "calling failure so it fails (without local)"
>     FAILUREOUT=$(failure)
>     # here set -eu works so we will fail instead of getting here
>     echo "Internal error, set -eu didn't work even without local"
> }
> 
> cmd-subst-failure-with-local

The `local' builtin succeeds because the assignment is performed succesfully.

> cmd-subst-failure-without-local

In the absence of a command name, the assignment statement's return
status is dependent on whether or not there is a command substitution
in the assignment statement, and that command substitution's exit
status.

-- 
``The lyf so short, the craft so long to lerne.'' - Chaucer
                 ``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, ITS, CWRU    c...@case.edu    http://cnswww.cns.cwru.edu/~chet/

Reply via email to