The Computer Oracle

Whitespace is collapsed with echo >>

--------------------------------------------------
Hire the world's top talent on demand or became one of them at Toptal: https://topt.al/25cXVn
and get $2,000 discount on your first invoice
--------------------------------------------------

Music by Eric Matyas
https://www.soundimage.org
Track title: Peaceful Mind

--

Chapters
00:00 Whitespace Is Collapsed With Echo ≫≫
00:49 Accepted Answer Score 9
01:17 Thank you

--

Full question
https://superuser.com/questions/540161/w...

--

Content licensed under CC BY-SA
https://meta.stackexchange.com/help/lice...

--

Tags
#bash

#avk47



ACCEPTED ANSWER

Score 9


Like every other program, echo interprets strings separated by whitespace as different arguments.

After calling

echo foo    bar

the only data that gets passed to echo by the shell is that the first argument is foo and the second is bar.

To pass a whole string containing whitespaces as a single argument, enclose it in double quotes:

echo "foo    bar"

will print all four spaces.