using variable to make variable name in shell script -



using variable to make variable name in shell script -

i want echo $anmial0 , $animal1 using script below. line 7: ${animal$i}: bad substitution error message. what's wrong?

#!/bin/sh animal0="tiger" animal1="lion" i=0 while test $i -lt 2; echo "hey $i !" echo ${animal$i} i=`expr $i + 1` done

the problem shell performs single substitution pass. can forcefulness sec pass eval, comes usual security caveats (don't evaluate unchecked user input, etc).

eval echo \$animal$i

bash has various constructs help avoid eval.

shell

Comments

Popular posts from this blog

php - Android app custom user registration and login with cookie using facebook sdk -

django - Access session in user model .save() -

php - .htaccess Multiple Rewrite Rules / Prioritizing -