如何在bash中將變量的值用作另一個變量的名稱我想聲明一個變量,其名稱來自另一個變量的值,我編寫了以下代碼:a="bbb"$a="ccc"但沒起作用。完成這項工作的正確方法是什么?
3 回答

天涯盡頭無女友
TA貢獻1831條經驗 獲得超9個贊
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貢獻1827條經驗 獲得超8個贊
declare
!
John="nice guy"programmer=Johnecho ${!programmer} # echos nice guy
programmer=Inesdeclare $programmer="nice gal"echo $Ines # echos nice gal

森林海
TA貢獻2011條經驗 獲得超2個贊
foo=bar declare $foo=baz echo $bar baz
foo=bar read $foo <<<"baz"echo $bar baz
- 3 回答
- 0 關注
- 707 瀏覽
添加回答
舉報
0/150
提交
取消