On Tue, Jul 26, 2022 at 12:22:11PM +0200, Laszlo Ersek wrote:
On 07/26/22 12:17, Laszlo Ersek wrote:
On 07/26/22 10:11, Richard W.M. Jones wrote:
On Tue, Jul 26, 2022 at 07:13:41AM +0200, Laszlo Ersek wrote:
On 07/25/22 16:02, Eric Blake wrote:
+ for (( _i = 0; _i < $_cleanup_hook_count; ++_i )); do + local -n _hook=_cleanup_hook$_i + "${_hook[@]}"
BTW, "nameref" variables seem like a relatively new addition to bash; for example RHEL7 does not have them. Interestingly, the RHEL7 manual also does not document a nameref-like construct that *does* work in RHEL7, namely:
$ bar=foo $ baz=bar $ echo ${!baz} foo
Indeed it doesn't work on RHEL 7, eg:
$ make && make -C tests check TESTS=test-eflags.sh
leaves tests/eflags.{err,out} around.
Do you have a patch for this?
This should work:
local hook=_cleanup_hook$_i eval "\${${hook}[@]}"
Sigh, nesting quoting is always fun; I forgot the outermost quotes. So please make that:
eval "\"\${${hook}[@]}\""
So after quotes and variables are done this expands to: eval "${_cleanup_hook_X[@]}" It looks right to me -- and works in my limited test -- but I guess I'll let Eric decide on this one. Rich.
Thanks Laszlo
[...]
I wonder if the bash release notes mention "nameref" as a more flexible version of "indirect expansion"... Hm, nameref was new in bash-4.3 <https://lwn.net/Articles/589566/>, and RHEL7 has bash-4.2.46-35.el7_9, so the lack of "nameref" is understandable (not that it matters for upstream nbdkit :)); indirect expansion is not mentioned however as a similar feature.
Actually I'd like to keep things working on RHEL 7 if possible. It's still a widely used RHEL release.
Rich.
-- Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones Read my programming and virtualization blog: http://rwmj.wordpress.com virt-top is 'top' for virtual machines. Tiny program with many powerful monitoring features, net stats, disk stats, logging, etc. http://people.redhat.com/~rjones/virt-top