1

Please advice how to use the eval command in order to print the parameter value

for example

bash

a=1
b=2
c=3


for i in ` echo a b c `
> do
> echo "$i=` eval $i ` "
> done

bash: a: command not found
a= 
bash: b: command not found
b= 
bash: c: command not found
c= 

why I don’t get the requested output (from for loop command)

 a=1
 b=2
 c=3
2

There is no need to use eval in this instance

eval $i forces eval to evaluate the contents of i as a command - this is why you see errors such as b: command not found being reported

A better way would be to print parameter values with bash using variable deferencing

for i in a b c; do echo "$i=${!i}"; done
a=1
b=2
c=3

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.