Below is a script for dynamic variable creation
Code:
#!/bin/bash
variableName="test"
variableVal="123"
eval ${variableName}=`echo -ne \""${variableVal}"\"`
echo $test #"test" variable created dynamically using eval
When I execute this with the first line set to #!/bin/sh, the result is
eval: 1: 123: not found
But when I execute it as is above noting #!/bin/bash, it works as desired and the result is
123
I am wondering what is the difference, and what is the equivalent of this script if it is written in sh.
Thanks!
Regards,
archieval