You are not logged in.

#1 2014-10-28 15:00:08

sharkwouter
Member
Registered: 2013-11-30
Posts: 6

[Solved]Weird behaviour echo and printf

The manual page of echo states that you can print newlines if you use the -e option by adding \n to the string, but That isn't working for me. When running "/bin/echo -e top\nbottom" the output will be "topnbottom". Same with printf, running "/usr/bin/printf top\nbottom" give me the output "topnbottom".

This might be specific to bash, since it does print a newline when using fish shell. Those are the only 2 shells installed on my system, though.

What is causing this? It shouldn't be using the buildin echo and printf like that.

Last edited by sharkwouter (2014-10-28 15:23:10)

Offline

#2 2014-10-28 15:20:40

Nietzsche
Member
Registered: 2014-10-26
Posts: 15

Re: [Solved]Weird behaviour echo and printf

Looks like your string must be quoted ("string") in order for echo to interpret special characters.

Offline

#3 2014-10-28 15:22:45

sharkwouter
Member
Registered: 2013-11-30
Posts: 6

Re: [Solved]Weird behaviour echo and printf

Nietzsche wrote:

Looks like your string must be quoted ("string") in order for echo to interpret special characters.

Oh wow, you are right. Thanks for that one.

Offline

#4 2014-10-28 15:31:40

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 30,543
Website

Re: [Solved]Weird behaviour echo and printf

Alternatively you can escape the slash:

$ echo -e "one\ntwo"
one
two
$ echo -e one\\ntwo
one
two

"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman

Offline

Board footer

Powered by FluxBB