bug-bash
[Top][All Lists]
Advanced

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

${!variable@operator} does not work for variables without values; incons


From: Arfrever Frehtes Taifersar Arahesis
Subject: ${!variable@operator} does not work for variables without values; inconsistencies between present and absent [@] for @A and @a
Date: Wed, 19 Feb 2020 22:03:31 +0100

${!variable@operator} does not work for variables without values.
See empty values for all occurrences of ${!var@...} below.

${variable@A} does not work for scalar variables without values, but
interestingly ${variable[@]@A} works for them.
See difference between ${VAR1@A} and ${VAR1[@]@A} below.
However neither ${variable@A} nor ${variable[@]@A} works for arrays
without values.

Both ${variable@a} and ${variable[@]@a} work for scalar variables
without values.
However ${variable[@]@a} does not work for arrays without values.
See difference between ${VAR3@a} and ${VAR3[@]@a}, and between
${VAR5@a} and ${VAR5[@]@a} below.

(BASH 5.0.16.)

$ declare -lr VAR1
$ declare -lr VAR2=zzz
$ declare -alr VAR3
$ declare -alr VAR4=(zzz)
$ declare -Alr VAR5
$ declare -Alr VAR6=([0]=zzz)
$ declare -p VAR{1,2,3,4,5,6}
declare -rl VAR1
declare -rl VAR2="zzz"
declare -arl VAR3
declare -arl VAR4=([0]="zzz")
declare -Arl VAR5
declare -Arl VAR6=([0]="zzz" )
$ for operator in Q E P A a ; do for var in VAR{1,2,3,4,5,6} ; do echo
"var=${var}" ; eval "echo \"\\\${!var@${operator}}:
'\${!${var}@${operator}}'\"" ; eval "echo \"\\\${!var[@]@${operator}}:
'\${!${var}[@]@${operator}}'\"" ; eval "echo
\"\\\${${var}@${operator}}:    '\${${var}@${operator}}'\""  ; eval
"echo \"\\\${${var}[@]@${operator}}: '\${${var}[@]@${operator}}'\"" ;
echo ; done ; done
var=VAR1
${!var@Q}:    ''
${!var[@]@Q}: ''
${VAR1@Q}:    ''
${VAR1[@]@Q}: ''

var=VAR2
${!var@Q}:    ''
${!var[@]@Q}: ''
${VAR2@Q}:    ''zzz''
${VAR2[@]@Q}: ''zzz''

var=VAR3
${!var@Q}:    ''
${!var[@]@Q}: ''
${VAR3@Q}:    ''
${VAR3[@]@Q}: ''

var=VAR4
${!var@Q}:    ''
${!var[@]@Q}: ''
${VAR4@Q}:    ''zzz''
${VAR4[@]@Q}: ''zzz''

var=VAR5
${!var@Q}:    ''
${!var[@]@Q}: ''
${VAR5@Q}:    ''
${VAR5[@]@Q}: ''

var=VAR6
${!var@Q}:    ''
${!var[@]@Q}: ''
${VAR6@Q}:    ''zzz''
${VAR6[@]@Q}: ''zzz''

var=VAR1
${!var@E}:    ''
${!var[@]@E}: ''
${VAR1@E}:    ''
${VAR1[@]@E}: ''

var=VAR2
${!var@E}:    ''
${!var[@]@E}: ''
${VAR2@E}:    'zzz'
${VAR2[@]@E}: 'zzz'

var=VAR3
${!var@E}:    ''
${!var[@]@E}: ''
${VAR3@E}:    ''
${VAR3[@]@E}: ''

var=VAR4
${!var@E}:    ''
${!var[@]@E}: ''
${VAR4@E}:    'zzz'
${VAR4[@]@E}: 'zzz'

var=VAR5
${!var@E}:    ''
${!var[@]@E}: ''
${VAR5@E}:    ''
${VAR5[@]@E}: ''

var=VAR6
${!var@E}:    ''
${!var[@]@E}: ''
${VAR6@E}:    'zzz'
${VAR6[@]@E}: 'zzz'

var=VAR1
${!var@P}:    ''
${!var[@]@P}: ''
${VAR1@P}:    ''
${VAR1[@]@P}: ''

var=VAR2
${!var@P}:    ''
${!var[@]@P}: ''
${VAR2@P}:    'zzz'
${VAR2[@]@P}: 'zzz'

var=VAR3
${!var@P}:    ''
${!var[@]@P}: ''
${VAR3@P}:    ''
${VAR3[@]@P}: ''

var=VAR4
${!var@P}:    ''
${!var[@]@P}: ''
${VAR4@P}:    'zzz'
${VAR4[@]@P}: 'zzz'

var=VAR5
${!var@P}:    ''
${!var[@]@P}: ''
${VAR5@P}:    ''
${VAR5[@]@P}: ''

var=VAR6
${!var@P}:    ''
${!var[@]@P}: ''
${VAR6@P}:    'zzz'
${VAR6[@]@P}: 'zzz'

var=VAR1
${!var@A}:    ''
${!var[@]@A}: ''
${VAR1@A}:    ''
${VAR1[@]@A}: 'declare -rl VAR1='''

var=VAR2
${!var@A}:    ''
${!var[@]@A}: ''
${VAR2@A}:    'declare -rl VAR2='zzz''
${VAR2[@]@A}: 'declare -rl VAR2='zzz''

var=VAR3
${!var@A}:    ''
${!var[@]@A}: ''
${VAR3@A}:    ''
${VAR3[@]@A}: ''

var=VAR4
${!var@A}:    ''
${!var[@]@A}: ''
${VAR4@A}:    'declare -arl VAR4='zzz''
${VAR4[@]@A}: 'declare -arl VAR4=([0]="zzz")'

var=VAR5
${!var@A}:    ''
${!var[@]@A}: ''
${VAR5@A}:    ''
${VAR5[@]@A}: ''

var=VAR6
${!var@A}:    ''
${!var[@]@A}: ''
${VAR6@A}:    'declare -Arl VAR6='zzz''
${VAR6[@]@A}: 'declare -Arl VAR6=([0]="zzz" )'

var=VAR1
${!var@a}:    ''
${!var[@]@a}: ''
${VAR1@a}:    'rl'
${VAR1[@]@a}: 'rl'

var=VAR2
${!var@a}:    ''
${!var[@]@a}: ''
${VAR2@a}:    'rl'
${VAR2[@]@a}: 'rl'

var=VAR3
${!var@a}:    ''
${!var[@]@a}: ''
${VAR3@a}:    'arl'
${VAR3[@]@a}: ''

var=VAR4
${!var@a}:    ''
${!var[@]@a}: ''
${VAR4@a}:    'arl'
${VAR4[@]@a}: 'arl'

var=VAR5
${!var@a}:    ''
${!var[@]@a}: ''
${VAR5@a}:    'Arl'
${VAR5[@]@a}: ''

var=VAR6
${!var@a}:    ''
${!var[@]@a}: ''
${VAR6@a}:    'Arl'
${VAR6[@]@a}: 'Arl'

$

--
Arfrever Frehtes Taifersar Arahesis



reply via email to

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