I’ve defined a variable say:
bob_pants="fancy"
and now I want to reference the contents of $bobs_pants by using another variable.
name="bob"
item="pants"
Can I do something like:
echo "${name} has ${name}_${item} ${item}"
I want the output for the above to be "user bob has fancy pants"
So far I’ve only succeeded in getting "user bob has bob_pants pants"
I guess I need some way for${name}_${item} to be seen as ${bob_pants} but all the ways I tried to group the variables into one haven’t worked.
In
bash:The
${!var}notation evaluates to the variable named by$var. However, you can’t do: