I'm trying to get a list of specific variables and then the values of those variables?
#!/bin/bash
varA=1.3.5 # need this
varB=2.4.6 # need this
varC=3.6.9 # need this
ignoreA="Do not need"
ignoreB="Or this"
vars=`compgen -A variable | grep var`
for v in ${vars} ; do
echo "${p} = $${p}"
done
I get the list of the variables, but can't work out how to get the value of each of those variables in the for-loop? I've tried a number of different combinations but can't wrap my head around what this should be:
- ${$p}
- {$$p}
- $(${p})
for item in ${string}, btw, is generally a code smell and best avoided. If you want to track a list of things you can index into, iterate over, etc., use an array rather than a string for storing it. The caveats in BashPitfalls #1 apply; so does DontReadLinesWithFor. And in determining how to populate that array, be wary of BashPitfalls #50.