Thursday, February 22, 2018

Echo newline in Bash prints literal n



In Bash, tried this:



echo -e "hello\nworld"



But it doesn't print a newline, only \n. How can I make it print the newline?



I'm using Ubuntu 11.04.


Answer



You could use printf instead:



printf "hello\nworld\n"


printf has more consistent behavior than echo. The behavior of echo varies greatly between different versions.



No comments:

Post a Comment

plot explanation - Why did Peaches' mom hang on the tree? - Movies & TV

In the middle of the movie Ice Age: Continental Drift Peaches' mom asked Peaches to go to sleep. Then, she hung on the tree. This parti...