[prev in list] [next in list] [prev in thread] [next in thread] 

List:       bash-bug
Subject:    Re: readonly changes set -e behavior
From:       Eduardo Bustamante <dualbus () gmail ! com>
Date:       2017-02-21 22:30:39
Message-ID: CAOSMAuu9pxhnY9RgQBT2JJz80jRQBhvonn0Ua=G4usZ+cSssBw () mail ! gmail ! com
[Download RAW message or body]

On Tue, Feb 21, 2017 at 11:02 AM, Dennis Kuhn <d.kuhn@syseleven.de> wrote:
[...]
>
> When the variable s is set to readonly the script does not exit and echoes "abc":
>
> #!/bin/bash
> set -e
>
> readonly s=$(false)
> echo "abc"
[...]

This is a commonly reported issue. The moment you add the readonly
builtin, you're no longer seeing the exit code from the command
substitution, but the exit code from readonly. See:

https://lists.gnu.org/archive/html/bug-bash/2012-10/msg00075.html
Command substitution and errexit
http://lists.gnu.org/archive/html/bug-bash/2014-08/msg00036.html
'declare' does not honor '-e' in command substituted assignments - a
bug
http://lists.gnu.org/archive/html/bug-bash/2015-09/msg00109.html local
keyword hides return code of command substitution

One easy way to workaround this is to do:

s=$(...); readonly s


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic