Echo print in the same line

Default featured post

In shell scripting when echo command is used the output always is printed in the next line. For example,

$ echo "A"
$ echo "B"

Resulted in the output of two separate lines as follows,


If you want to print output in the same line you can use echo with -n parameter to avoid carriage return. Alternatively, you can use printf command which is a good replacement of echo command in shell (bash) scripting.

Printf is so close to C printf and has almost the same flexibility and lets you to print out put in forms of tabs. Bear in mind that bash printf does not include parentheses like C printf.

More information about both echo and printf can be found in its man page.