On Tue, Jul 26, 2022 at 06:56:04AM -0500, Eric Blake wrote:
On Tue, Jul 26, 2022 at 07:13:41AM +0200, Laszlo Ersek wrote:
> >
> > - for (( _i = 0; _i < ${#_cleanup_hook[@]}; ++_i )); do
> > - ${_cleanup_hook[_i]}
> > + 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
Oh. Okay, namerefs are out. But indirect variables aren't much better:
>
> However, I couldn't find a syntax that made this feature work with array
> variables. In particular, ${!name[@]} stands for "List of array keys".
On the web, I've found:
var=varname
tmp=${var}[@]
"${!tmp}"
https://mywiki.wooledge.org/BashFAQ/006
but that's still horrible; I'd rather just go for eval at this point.
>
> 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.
At least RHEL 7 has bash 4.2, which added 'local -ag' for declaring
global arrays even within function scope. Bash 4.1 (hello RHEL 6)
lacked even that.
Works for me on RHEL 7, thanks.
Rich.
At any rate, I'll push the patch to switch to something that
works on
bash 4.2 and RHEL 6 shortly.
--
Eric Blake, Principal Software Engineer
Red Hat, Inc. +1-919-301-3266
Virtualization:
qemu.org |
libvirt.org
_______________________________________________
Libguestfs mailing list
Libguestfs(a)redhat.com
https://listman.redhat.com/mailman/listinfo/libguestfs
--
Richard Jones, Virtualization Group, Red Hat
http://people.redhat.com/~rjones
Read my programming and virtualization blog:
http://rwmj.wordpress.com
virt-builder quickly builds VMs from scratch
http://libguestfs.org/virt-builder.1.html