Вопрос

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?

Это было полезно?

Решение

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.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top