Eval

Eval!

shell> a=abc
shell> b=def
shell> $a=ghi    ///Wrong !   $a-->only as right value! 
shell> eval $a=nice  /// Right!
shell> echo $abc
nice
shell>eval  "string" ///eval 会和后面的字符串合并起来 as a single commnd!


#!/bin/bash
#ind-ref.sh: 间接变量引用.
#访问一个以另一个变量内容作为名字的变量的值.

a=letter_of_alphabet # 变量"a"的值是另一个变量的名字.
letter_of_alphabet=z
z=abcdef

echo

# 直接引用.
echo "a = $a" # a = letter_of_alphabet

# 间接引用.
eval a=\$$a
echo "Now(one) a = $a" # now a = z

# 2次间接引用.
#+ 加上上面那一次!
eval a=\$$a
echo "Now(tow) a = $a" # now a = abcdef

echo

上一篇:用文件有效生成数组


下一篇:关于pl/sql数据库下拉中选项为空的问题