Whitespace concatenation in Bash Whitespace concatenation in Bash bash bash

Whitespace concatenation in Bash


The problem may be because $empty_space has only spaces. Then, to output them you have to surround it in double quotes:

echo "${empty_space}some_other_thing"

You can try more interesting output with printf for example to obtain several spaces. For instance, to write 20 spaces:

v=`printf '%20s' ' '`


The strings can be created using parameter substitution.The substitution ${str:offset:length} returns a substring of str :

space80='                                                                                'hash80='################################################################################'progress_bar=${hash80:0:$progress_length-$begin+1}empty_space=${space80:0:$end-$middle+1}echo -n "$empty_space$progress_bar"


I understand your problem as I had exactly the same.

My solution was to concatenate a temporary character instead of a whitespace, say for example , and then, at the end, replace all their occurences with sed by a whitespace :

echo $myString | sed 's/☼/ /g'

I hope it will help you !