[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 18:26:58 -0400 |
User-agent: |
Cyrus-JMAP/3.7.0-alpha0-755-g3e1da8b93f-fm-20220708.002-g3e1da8b9 |
On Fri, Jul 15, 2022, at 12:13 PM, Robert Stoll wrote:
> Following a script to reproduce the problem:
>
> =========================================================================================
>
> #!/usr/bin/env bash
> set -e
>
> function trapHook(){
> echo "$1"
> local -r readonlyVar=$1
> }
>
> function test1(){
> local -r readonlyVar=2
> trap 'trapHook $readonlyVar' EXIT
> }
> function test2(){
> local -r readonlyVar=2
> trap 'trapHook $readonlyVar' EXIT
> exit 0
> }
> test1 # works as exit happens outside of test1
> test2 # fails with ./src/test.sh: line 6: local: readonlyVar: readonly
> variable
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
The trap is incidental -- you can observe the same behavior without
it -- but it's worth noting that the trap command runs in the context
from which the shell exits, not the context in which the trap is
set.
What do you think the bug is, exactly? How do you think this should
behave?
--
vq
- local -r issue in conjunction with trap, Robert Stoll, 2022/07/15
- Re: local -r issue in conjunction with trap,
Lawrence Velázquez <=
- Re: local -r issue in conjunction with trap, Lawrence Velázquez, 2022/07/15
- Re: local -r issue in conjunction with trap, Koichi Murase, 2022/07/15
- Re: local -r issue in conjunction with trap, Lawrence Velázquez, 2022/07/15
- Re: local -r issue in conjunction with trap, Chet Ramey, 2022/07/17
- Re: local -r issue in conjunction with trap, Koichi Murase, 2022/07/17
- Re: local -r issue in conjunction with trap, Chet Ramey, 2022/07/18
- Re: local -r issue in conjunction with trap, Chet Ramey, 2022/07/18
Re: local -r issue in conjunction with trap, Robert Elz, 2022/07/16
Re: local -r issue in conjunction with trap, Dale R. Worley, 2022/07/16