I'm trying to combine some text to a variable and output the value of the combined variable. For example:
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
Output would be:
FILE
testFILE
/tmp/some_file.log <-- this is what I can't figure out.
Any ideas?
If I'm not using the correct terminology please correct me.
Thanks, Jared
Try the following:
#!/bin/bash
testFILE=/tmp/some_file.log
function test_param {
echo $1
echo test$1
varName=test$1
echo ${!varName}
}
test_param FILE
The ! before varName indicates that it should look up the variable based on the contents of $varName, so the output is:
FILE
testFILE
/tmp/some_file.log
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With