I hope to construct a string, expand the value of a variable whose name is equal to the string, and use that value as one of the arguments in a command. I cannot figure out if it is possible without incorporating the eval command, which most seem to advise against using.
Using a remote system, I wish to iterate through a customer list and collect disk usage statistics for logs.
customer0="/volume1/bob"
customer1="/volume1/joe"
num_of_customers=2
for ((i=0;i<$num_of_customers;i++))
do
ssh [email protected] du -sb customer$i
done
The resulting value for customer$i when i=0 is customer0
The desired outcome is /volume1/bob
Is there a safe way to accomplish this? I've searched for answers, but I struggle to phrase the question properly.