[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Local declaration with nameref
From: |
uzibalqa |
Subject: |
Local declaration with nameref |
Date: |
Tue, 02 May 2023 22:36:31 +0000 |
I have the following bash function that is not making any sense to me,
finding it quite confusing.
After the function call, when I echo "$signal", I are printing the value of the
variable signal that was passed as an argument to the function. Since the
function
modifies the value of _signal which is passed by reference to signal outside of
the function, the value of signal is also changed to "SUBSCRIPT".
Yet, the variable gives the impression that it has local context only inside
the function.
marin () {
local -n _signal="$1" _modes="$2"
[[ :"$_modes": != *:"$_signal":* ]] && _signal='SUBSCRIPT'
}
modes="ITERATE:COUNTER"
signal="foo"
marin signal modes
echo "$signal"
- Local declaration with nameref,
uzibalqa <=