Consider the following bash transcript:
~$ x="echo -n abc "
~$ $x && echo xyz
abcxyz
~$
Out of curiosity (please indulge me), I want to have a bash variable containing the echo -n
command outputting something. I want to know if it is possible to define it in a way to preserve the trailing space.
An obvious option is use the quotes:
~$ x="echo -n \"abc \""
~$ $x && echo xyz
"abc "xyz
~$
But these quotes pollute the output.
Of course, I can prepend the space to the second echo command:
~$ x="echo -n abc "
~$ $x && echo " xyz"
abc xyz
~$
But the purpose of the question is to understand if x
can be changed in a way that $x
represents echo -n
with the trailing space without redundant quotes in the output.
Thank you very much.