On Fri, Jul 15, 2022, at 7:06 PM, Koichi Murase wrote: > 2022年7月16日(土) 7:28 Lawrence Velázquez <v...@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