如何在bash中将变量的值用作另一个变量的名称我想声明一个变量,其名称来自另一个变量的值,我编写了以下代码:a="bbb"$a="ccc"但没起作用。完成这项工作的正确方法是什么?
3 回答
qq_花开花谢_0
TA贡献1835条经验 获得超7个赞
eval
name_of_variable=abceval $name_of_variable="simpleword" # abc set to simpleword
eval $name_of_variable="word splitting occurs"
eval $name_of_variable="\"word splitting occurs\"" # not anymore
safevariable
eval $name_of_variable=\$safevariable # note escaped dollar sign
eval
eval 'abc=$safevariable' # dollar sign now comes to life inside eval!
safevariable
*
$
name_of_variable
当年话下
TA贡献1890条经验 获得超9个赞
declare
!
John="nice guy"programmer=Johnecho ${!programmer} # echos nice guy
programmer=Inesdeclare $programmer="nice gal"echo $Ines # echos nice gal
慕容708150
TA贡献1831条经验 获得超4个赞
foo=bar declare $foo=baz echo $bar baz
foo=bar read $foo <<<"baz"echo $bar baz
- 3 回答
- 0 关注
- 993 浏览
添加回答
举报
0/150
提交
取消