Let use replicate this issue.
echo "Value of VAR0 is $VAR0"
Save this file and execute this script.
abc.sh: line 4: VAR0=abc: command not found
Value of VAR0 is
If you see I am getting command not found error.
This is due to the line VAR$i=$VAR1, in which we are trying to substitute two variable at a time, one on RHS and other on LHS. This is not possible by default in Shell scripting. First we have to substitute "i" value then substitute $VAR1 value. To resolve this issue we have to use eval command which gives us second chance to execute a command.
Modified version of above script as below.
echo "VAlue of VAR0 is $VAR0"
VAlue of VAR0 is abc
Hope this helps to resolve dynamic assignmet of variables.
Latest posts by Surendra Anne (see all)
- Review: Whizlabs Practice Tests for AWS Certified Solutions Architect Professional (CSAP) - August 27, 2018
- How to use ohai/chef-shell to get node attributes - July 19, 2018
- wget download a file to a directory in Linux/Unix - June 4, 2018
- GIT: How to compare two GIT branches? - June 3, 2018
- Online training on Linux Bash shell scripting - February 8, 2018