[Top][All Lists]

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

local -r issue in conjunction with trap

From: Robert Stoll
Subject: local -r issue in conjunction with trap
Date: Fri, 15 Jul 2022 16:13:40 +0000 (UTC)


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

Please let me know in case you need further information.

Kind regards,
Robert Stoll

+41 31 328 33 60

Tegonal Genossenschaft              
Wasserwerkgasse 2
3011 Bern, Switzerland

reply via email to

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