我想根據另一個變量在腳本中創建一個變量。在unix腳本里面創建變量
我只是不知道需要在我的代碼中調整什麼,如果有可能的話。 我正在簡化我的代碼以便您理解,所以這不是原始代碼。
的代碼是這樣說:
#!/bin/csh -f
set list_names=(Albert Bela Corine David)
set Albert_house_number=1
set Bela_house_number=2
set Corine_house_number=3
set David_house_number=4
foreach name ($list_names)
#following line does not work....
set house_number=$($name\_house_number)
echo $house_number
end
所需的輸出應該是:
1
2
3
4
感謝您的幫助。
可能有助於閱讀:[是否有可能從bash中的其他變量生成變量名?](http://stackoverflow.com/q/3963494/1983854) – fedorqui
@fedorqui這些都看起來bash-,或至少POSIX特定。 'csh'是一個完全不同的野獸(值得大寫「B」)。 – Wintermute
同樣的問題[也在這裏回答](http://stackoverflow.com/questions/27604063/variable-of-variable/27606472?s=12|5。2651) – Carpetsmoker