bug-bash
[Top][All Lists]
Advanced

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

Re: nounset option: Error message points to the wrong variable when acce


From: Emanuele Torre
Subject: Re: nounset option: Error message points to the wrong variable when accessing associative arrays
Date: Thu, 11 May 2023 14:07:12 +0200
User-agent: Mutt/2.2.10 (2023-03-25)

On Thu, May 11, 2023 at 10:54:36AM +0000, Baumann, Moritz wrote:
> Sorry for bothering you again, but I might have misremembered: I looked
> through the manual again and could not find any mention of this behavior
> in any of the following sections:
> 
>  * Arrays
>  * Bash Conditional Expressions
>  * Conditional Constructs
> 
> Maybe I'm blind, but is it possible that the manual never mentions or
> implies that -v expands variables by itself?

I am not sure if it is ever explicitly mentioned in the manual page, but
note that it is not specific to  test -v;  it also applies to basically
any builtin that take "varname" arguments (I think getopts, and printf's
%n format specifier are probably the only exceptions, excluding builtins
that accept an array name like read's -a option and mapfile):

    unset -v 'arr[i++]'; unset -v 'assoc[$key]'
    read -r 'assoc[$key]'; read -r 'arr[j--]' 'arr[k--]'
    printf -v 'assoc[$k]' %s "${hi[@]}" "${hello[@]}"
    typeset 'foo[$k]=$bar$(echo hi)'
    # ... etc ...

 emanuele6



reply via email to

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