Domanda

In a ksh-snippet like the following

iname=FA
USER_FA=xyz 
USER_CS=test
TDUSER=USER_$iname
${!TDUSER}

${!TDUSER} does not work as expected. Why?

È stato utile?

Soluzione

The syntax ${!var} works in bash but not ksh93. Variable indirection in ksh uses namerefs:

$ iname=FA
$ USER_FA=xyz
$ nameref TDUSER=USER_$iname
$ echo "${TDUSER}"
xyz

In ksh93, the ! modifier is used to get the list of indexes from an array: ${!name[@]} during parameter substitution.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top