bug-bash
[Top][All Lists]
Advanced

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

Re: Difference between assignment via nameref vs `printf -v`?


From: lolilolicon
Subject: Re: Difference between assignment via nameref vs `printf -v`?
Date: Mon, 1 Sep 2014 00:19:10 +0800

On Sun, Aug 31, 2014 at 12:20 PM, lolilolicon <address@hidden> wrote:
> Assignment to a subscripted array variable behaves differently for
> nameref vs `printf -v`, as shown below.
>
> Assignment via nameref variable:
>
> declare -a arr=()
> func() {
>   local -n ref=$1
>   ref='nameref'
> }
> func 'arr[0]'
> declare -p 'arr[0]' arr
>
> --- output ---
> declare -- arr[0]="nameref"
> declare -a arr='()'

It's a damn bug alright. Just curious though, shouldn't assignments to
via nameref variables re-use the same code as `printf -v`?

>
> v.s.
>
> Assignment via `printf -v`:
>
> declare -a arr=()
> func() {
>   printf -v "$1" 'printf -v'
> }
> func 'arr[0]'
> declare -p 'arr[0]' arr
>
> --- output ---
> ap.sh: line 10: declare: arr[0]: not found
> declare -a arr='([0]="printf -v")'
>
>
> Is subscripted array variable allowed as argument to `declare -p` in bash?
> A quick test seems to suggest it's not -- consistent with the `printf
> -v` behavior.
>
> Is there a legitimate explanation for this?



reply via email to

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