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