Shell中,间接引用(打印变量的变量)

Shell中的二次引用:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
a=b
b=123
echo $a # is b
echo ${!a} # is 123
a=b b=123 echo $a # is b echo ${!a} # is 123
a=b
b=123

echo $a     # is b
echo ${!a}  # is 123

如上所属,使用${!var},就可以获得变量var中存储的变量的变量了~

Leave a Reply

Your email address will not be published. Required fields are marked *