How do I echo a string with multiple spaces in bash "untouched"?

Put your variable inside double quote to prevent field splitting, which ate your spaces:

$ MYCUSTOMTAB='     '
$ echo "${MYCUSTOMTAB}blah blah"
     blah blah

As suggested in this answer quoting the variable is enough.

The reason why quoting is needed in your case is because without it bash applies the split+glob operator onto the expansion of $MYCUSTOMTAB. The default value of $IFS contains the TAB character, so in echo -e $MYCUSTOMTAB"blah blah", $MYCUSTOMTAB is just split into nothing so it becomes the same as if you had written:

echo -e "blah blah"

(you probably don't want -e here btw).

You can also use printf instead of echo:

printf '%s\n' "$MYCUSTOMTAB"

printf '%s\n' "${MYCUSTOMTAB}blah blah"

Or if you want printf to do the same kind of \n, \t expansions that echo -e does, use %b instead of %s:

printf '%b\n' "${MYCUSTOMTAB}blah blah"

For reference read Why is printf better than echo?


I think you just have to use double quotes for your variable

echo -e "$MYCUSTOMTAB"."blah blah"