I am trying to use the variable $i from a for statement as part of another variable name within an if statement.
I have the following function as part of a script:
online () {
for i in $processors; do
if ping -c1 $i &> /dev/null; then
${i}status="Online"
else
${i}status="Offline"
fi
done
}
The output of the if
statement is treated as a command and not as a declared variable. I want to use the dynamic variable several times in another function later in the script.
Is there any way to do this or do I need to work out another solution?