我正在尝试将一些文本组合到一个变量中并输出组合变量的值。例如:
testFILE=/tmp/some_file.log
function test_param {
echo $1
echo test$1
echo $(test$1) #this is where I want to output the value of the combined variable
}
test_param FILE
输出将是:
FILE
testFILE
/tmp/some_file.log <-- this is what I can't figure out.
有什么想法吗?
如果我使用的术语不正确,请纠正我。
谢谢, 贾里德
最佳答案
尝试以下操作:
#!/bin/bash
testFILE=/tmp/some_file.log
function test_param {
echo $1
echo test$1
varName=test$1
echo ${!varName}
}
test_param FILE
varName
前的!
表示要根据$varName
的内容查找变量,所以输出为:
FILE
testFILE
/tmp/some_file.log
关于linux - Bash 脚本变量替换,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9136099/