How to avoid space after bash variable in string?
Just enclose variable in braces:
echo -e "${Red}Note: blabla${NC}".
See more detail about Parameter Expansion.
See also great answer Why printf is better than echo? if you care about portability.
What you should get into the habit of using is printf:
printf '%sNote: blabla%s\n' "$Red" "$NC"
Where each %s
replace a variable. And the -e
is not needed as printf accepts backslash values \n,\t, etc in a portable manner.
Remember that echo -e
is not portable to other shells.
Other options:
You could use two commands that concatenate their output:
echo -ne "$Red"; echo -e "Note: blabla$NC"
You could use simple string concatenation:
echo -e "$Red""Note: blabla$NC"
Or you could make use of { }
to avoid name-text confusions:
echo -e "${Red}Note: blabla$NC"