Frage

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?

War es hilfreich?

Lösung

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.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top