Echo print in the same line

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

echo A

echo B

The output of two above echo will be like



If you want to print output in the same line you can use echo with ‘-n’ parameter to avoid printing output in the next line or 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 their man pages.

send your idea to

Leave a Reply

Your email address will not be published. Required fields are marked *