bug-bash
[Top][All Lists]
Advanced

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

local assigned from command substitution disobeys set -eu


From: Ville Oikarinen
Subject: local assigned from command substitution disobeys set -eu
Date: Tue, 30 Dec 2014 14:03:01 +0200

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:

#!/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
cmd-subst-failure-without-local



reply via email to

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