Little Girl's Mostly Linux Blog

EchoVsPrintf

Echo vs printf

This page was last updated on April 4, 2012.

This is an observation of the behavior of echo vs printf when used on the command line. This behavior may not cause any issues when used inside a script.

Echo does what you’d expect it to do:
user@computer:~$ echo HELLO
HELLO
user@computer:~$
Printf lands inside my prompt:
user@computer:~$ printf HELLO
HELLOuser@computer:~$
To get printf to do what echo does takes the addition of the \n code for a newline:
user@computer:~$ printf "HELLO\n"
HELLO
user@computer:~$


Obligatory Happy Ending

And they all lived happily ever after. The end.

Leave a Comment »

No comments yet.

RSS feed for comments on this post. TrackBack URI

Comment:

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Blog at WordPress.com.

%d bloggers like this: