Hi Unfortunately I have never built bash on my own and it would probably take me too much time to do it. Thus, I am writing to this e-mail in the hope that someone more experienced can try to reproduce it with the latest version. I do hope that my bug-report helps nonetheless to improve bash.
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 ========================================================================================= > bash -version GNU bash, version 5.0.17(1)-release (x86_64-pc-linux-gnu) Copyright (C) 2019 Free Software Foundation, Inc. License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html> This is free software; you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law. > lsb_release -d Description: Ubuntu 20.04.4 LTS > uname -r 5.15.0-41-generic Please let me know in case you need further information. Kind regards, Robert Stoll robert.st...@tegonal.com +41 31 328 33 60 Tegonal Genossenschaft Wasserwerkgasse 2 3011 Bern, Switzerland http://tegonal.com -- http://twitter.com/tegonal http://github.com/tegonal