This question already has an answer here:
It is often said that variables should be double quoted when used.
In the following example I want to have the command
echo "You can't see me" in a variable and run it in such a way that the output is
You can't see me. This is the end goal.
$ cmd="echo \"You can't see me\"" $ echo "$cmd" echo "You can't see me" $ $cmd "You can't see me" $ "$cmd" echo "You can't see me": command not found
$cmd ran and it included double quotes which I did not want to have, and following the recommendation of double quoting the variables led to an error.
Does the recommendation have exceptions despite the fact that resources say that they always should be used?
I know how I can get the result that I want by running
eval "$cmd" (or without the double quotes), or by an appropriate transformation on the output after running
$cmd (without double quotes), but how do I avoid this issue?