[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: readonly changes set -e behavior
From: |
Eduardo Bustamante |
Subject: |
Re: readonly changes set -e behavior |
Date: |
Tue, 21 Feb 2017 16:30:39 -0600 |
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