[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[sr #111159] two obscure variable-indirection failures in non-interactiv
From: |
anonymous |
Subject: |
[sr #111159] two obscure variable-indirection failures in non-interactive shells |
Date: |
Sat, 7 Dec 2024 03:47:06 -0500 (EST) |
URL:
<https://savannah.gnu.org/support/?111159>
Summary: two obscure variable-indirection failures in
non-interactive shells
Group: The GNU Bourne-Again SHell
Submitter: None
Submitted: Sat 07 Dec 2024 08:47:00 AM UTC
Category: None
Priority: 5 - Normal
Severity: 3 - Normal
Status: None
Privacy: Public
Assigned to: None
Originator Email: gsteemso@gmail.com
Open/Closed: Open
Discussion Lock: Any
Operating System: Mac OS
_______________________________________________________
Follow-up Comments:
-------------------------------------------------------
Date: Sat 07 Dec 2024 08:47:00 AM UTC By: Anonymous
I recently discovered two distinct flaws in Bash’s variable-indirection
handling. They are easiest to reproduce in non-interactive shells, and one
occurs only when it is executed as sh rather than as bash. (It could be a
POSIX mode thing rather than a sh emulation thing, it’s hard to tell.)
Consider this example code:
TEXT_word='this is an example'
arg='word'
var_name="TEXT_${arg}"
echo "${!var_name}"
This ought to echo “this is an example”, and indeed in interactive mode,
it does exactly that. However, if the shell was invoked as sh, ${!var_name}
does not make an indirect reference but rather emits an error complaining that
“TEXT_word” is not a valid variable name. This appears to only happen
under specific conditions, which I _believe_ are always satisfied if the shell
is non-interactive but may not be limited to that circumstance. In any case,
the error goes away if you try it without the underscore.
Regardless of underscores, in any sh emulation mode or in non-interactive
normal-bash mode, "${!var_name}" seems to always evaluate as empty. Nothing I
could think of would induce it to work. Fortunately, “declare -n
var_name="TEXT_${arg}"; echo "${var_name}"” does the same job, but from my
perspective it does so far less intuitively.
I am running what, when last I checked, is the most recent tarball release of
bash – “5.2.37(1)-release”, to be exact – in 64-bit mode under Mac OS
10.5.8 on a Power Macintosh G5.
_______________________________________________________
Reply to this item at:
<https://savannah.gnu.org/support/?111159>
_______________________________________________
Message sent via Savannah
https://savannah.gnu.org/
signature.asc
Description: PGP signature
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [sr #111159] two obscure variable-indirection failures in non-interactive shells,
anonymous <=