On Tue, Feb 21, 2017 at 11:02 AM, Dennis Kuhn <d.k...@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

Reply via email to