I pass a list of commands to a bash script through an environment variable as shown in the example below:
CMDS=' date > date.txt cat date.txt date | rev ' script What is the correct way to execute these commands in the bash script ?
I did the following and it seams to work. Is it correct ?
#! /bin/bash bash -c "$CMDS"
'it should be correct. Example for a problematic CMDS string would be:CMDS='echo "hello world"; echo ';echo $0'; echo "good bye"'."instead of'and escape everything which is problematic, like so:CMDS="echo \"hello world\"; echo ';echo \$0'; echo \"good bye\"".