变量的间接引用,两种不同的实现方法如下两例:
eg1:
$Message=Hello
$Hello="Good morning"
$echo "Message=$Message" #直接引用
Message=Hello
$eval Message=\$$Message #间接引用
$echo "Now Message=$Message"#最后两句合为一句eval echo "Now Message=\$$Message“
Now Messsage=Good morning
$
eg2:
$Message=Hello
$Hello="Good morning"
$echo ${Message}
Hello
$echo ${!Message}
Good morning
$Hello="Hello again"
$echo ${!Message}
Hello again
$
阅读(1041) | 评论(0) | 转发(0) |