I have a script which contains sections that store a command to a variable, prints out the command, then executes it.
Example:
Code:
MYCOMMAND="cp file1.txt $NEWFILE"
echo "Running $MYCOMMAND"
$MYCOMMAND
The above works when I save a single command to the string like I did above. However I want to store a string made up of multiple commands separated by && or ;. Example:
Code:
MYCOMMAND="cp file1.txt $NEWFILE && rm file1.txt && echo done"
echo "Running $MYCOMMAND"
$MYCOMMAND
When I separate the commands with && or ;, the whole string is echoed correctly, but only the first command actually gets executed. So the cp in the above example get executed, the rm and 'echo done' are not run.
How I can save a string with multiple commands in it to a single variable, echo that variable so the commands that are going to be run are printed out first, and then actually run the commands stored in that variable?