![](/img/trans.png)
[英]How to refer to a variable which is in a common script and the variable name in a file in a UNIX shell script
[英]How to pass variable name from a file and use that variable in script in unix
我在 unix 中有一個配置文件
Variable_name:sequences:Status
ABC:1234:/path/txt
and I have a script in unix as
$ABC="select * from table"
我想從文件中傳遞變量名並將腳本中的變量與腳本中的值一起使用。
所以我需要像這樣運行腳本
for i in /path/file_config;
$Variable=ABC
echo $variable # need result "select* from table"
請幫助我
在bash
(但不是其他 shell)中, ${!foo}
是一個間接引用,它擴展為$foo
中命名的變量的值。
所以,
ABC="select * from table"
name=ABC
echo "${!name}"
將顯示select * from table
對上面 Shawn 的回復稍加改進:
for Variable_name in `awk -F: '{ print $1 }' /path/file_config`; do
Variable=$Variable_name
echo ${!Variable}
done
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.