Printf example in bash does not create a newline
Posted
by WolfHumble
on Stack Overflow
See other posts from Stack Overflow
or by WolfHumble
Published on 2010-04-20T15:43:25Z
Indexed on
2010/04/20
15:53 UTC
Read the original article
Hit count: 141
Working with printf
in a bash script, adding no spaces after "\n"
does not create a newline, whereas adding a space creates a newline, e. g.:
No space after
"\n"
NewLine=`printf "\n"` echo -e "Firstline${NewLine}Lastline"
Result:
FirstlineLastline
Space after
"\n "
NewLine=`printf "\n "` echo -e "Firstline${NewLine}Lastline"
Result:
Firstline Lastline
Question: Why doesn't 1. create the following result:
Firstline
Lastline
I know that this specific issue could have been worked around using other techniques, but I want to focus on why 1. does not work.
© Stack Overflow or respective owner