NL=$'\n'
CMD=""
CMD="$CMD echo Hello ; $NL"
CMD="$CMD echo World ; $NL"
$CMD
The above code gives the following output, the echo
globing everything after it.
Hello ; echo World ;
Neither the new line character nor the semicolon does work here. What is going wrong?
For enabling interpretation of backslash escapes you have to add -e flag to echo.
Putting line feed into NL variable.
Setting CMD to empty string.
Resetting CMD, since old CMD is "" then new is " echo Hello ; \n"
Resetting CMD, since old CMD is " echo Hello ; \n" then new is " echo Hello ; \n echo World ; \n"