bug-bash
[Top][All Lists]
Advanced

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

Re: local -r issue in conjunction with trap


From: Lawrence Velázquez
Subject: Re: local -r issue in conjunction with trap
Date: Fri, 15 Jul 2022 19:20:49 -0400
User-agent: Cyrus-JMAP/3.7.0-alpha0-755-g3e1da8b93f-fm-20220708.002-g3e1da8b9

On Fri, Jul 15, 2022, at 7:06 PM, Koichi Murase wrote:
> 2022年7月16日(土) 7:28 Lawrence Velázquez <vq@larryv.me>:
>> You can't shadow a readonly variable:
>>
>> https://lists.gnu.org/archive/html/bug-bash/2019-03/msg00152.html
>> https://lists.gnu.org/archive/html/bug-bash/2019-03/msg00153.html
>> https://lists.gnu.org/archive/html/bug-bash/2020-04/msg00201.html
>> https://lists.gnu.org/archive/html/bug-bash/2020-04/msg00204.html
>
> We can shadow local readonly variables. What we cannot are global
> readonly variables.

Hm, you are right.  I thought I'd tested that, but I must have done
it wrong.


> It seems to me a bug. While the following works,
>
> $ bash-dev -ec 'T(){ local -r v=; }; trap T 0; F() { local -r v=; exit; }; F'
>
> the following fails
>
> $ bash-dev -e <<< 'T(){ local -r v=; }; trap T 0; F() { local -r v=; exit; }; 
> F'
> main: line 1: local: v: readonly variable
>
> Tested on the current devel 87a6e89e (+ define(relstatus, release) in
> configure.ac)

Same with 5.1.16.  It also fails when run as a script file:

    % cat /tmp/foo.bash
    set -e

    T() {
        local -r v=
    }

    trap T 0

    F() {
        local -r v
        exit
    }

    F
    % bash /tmp/foo.bash
    /tmp/foo.bash: line 4: local: v: readonly variable


-- 
vq



reply via email to

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