I have a string variable which contains a loop.
loopVariable="for i in 1 2 3 4 5 do echo $i done"
I want to pass this variable to a bash command inside the shell script. But i am always getting an error
bash $loopVariable
i've tried also
bin/bash $loopVariable
But it also doesn't work. Bash treats the string giving me an error. But theoretically it execute it. I am not sure what am i doing wrong
bash: for i in 1 2 3 4 5 do echo $i done: No such file or directory
I have also tried to use this approach using while loop. But getting the same error
i=0
loopValue="while [ $i -lt 5 ]; do make -j15 clean && make -j15 done"
bash -c @loopValue
when I use bash -c "@loopValue" i get following error
bash: -c: line 0: syntax error near unexpected token `done'
and when i use just use bash -c @loopValue
[: -c: line 1: syntax error: unexpected end of file
whileloop should bewhile [ $i -lt 5 ]; do make -j15 clean && make -j15; done, (missing;beforedone), and your bash command:bash -c $loopValue, notbash - c @loopValue.bash -c "$loopValue"