For example,
create a bash tmp.sh
script with the following,
export tmp=abc
read _test
echo "$_test"
Execute bash tmp.sh
Input '$tmp/def'.
Expected result: 'abc/def'
Actual result: '$tmp/def'
For example,
create a bash tmp.sh
script with the following,
export tmp=abc
read _test
echo "$_test"
Execute bash tmp.sh
Input '$tmp/def'.
Expected result: 'abc/def'
Actual result: '$tmp/def'
check this
eval "echo $_test"
or
bash -c "echo $_test"
Edit Latter (bash -c
) uses sub-shell which is safe in comparison with eval
You can use the envsubst
command to substitute environment variables like this:
echo "$_test" | envsubst
or, since this is in bash:
envsubst <<<"$_test"
This is significantly safer than either eval
or bash -c
, since it won't do anything other than replacing instances of $var
or ${var}
with the corresponding variable values.