bug-bash
[Top][All Lists]
Advanced

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

Re: {varname} for redirection does not work with arrays


From: Bash M'head
Subject: Re: {varname} for redirection does not work with arrays
Date: Wed, 28 Mar 2012 18:27:00 -0000
User-agent: G2/1.0

On Nov 5, 12:34 pm, Stephane CHAZELAS <stephane_chaze...@yahoo.fr>
wrote:
> 2011-11-2, 12:01(-06), unkn...@vmw-les.eng.vmware.com:
> [...]> Description:
> >    If {varname} is an assoc. array in a redirection the exec will fail
> >    The [] should not be confused with pathname expansion just like ${}.
>
> > Repeat-By:
> >    $ declare -A array
> >    $ exec {array[key]}<file
>
> [...]
>
> In the documentation, it's {VARNAME}<file, so bash works as
> documented.
>
> zsh doesn't support {array[key]}<file either.
>
> ksh does though it's not documented (documented the same as
> bash).
>
> The work around is easy though:
>
> $ declare -A array
> $ exec {var}<file
> $ array[key]=$var
>
> --
> Stephane

Hello Stephane,
    The workaround is trivial, its just inconsistent (with other parts
of bash).
I can say:

$ declare -A array
$ read -r 'array[key]' <<< 'foo'

This also makes arrays more directly useful.

$ declare -A fd
$ local fifo
$ exec {fifo}<"${fifo_path}"
$ fd[fifo]="${fifo}"
$ unset fifo

becomes

$ declare -A fd
$ exec {fd[fifo]}<"${fifo_path}"


reply via email to

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