Use the -n option to echo without appending a new line

$ echo -n "Hello out there"

One case this is useful for is if you have an interactive program that requests information.

So if you just did the following,

#!/bin/bash

echo "Enter a color: ";
read color;

The cursor to enter the color would be on a new line below Enter a color:.

If you use the following code,

#!/bin/bash

echo -n "Enter a color: ";
read color;

the cursor will be just after the statement Enter a color: so that they line up. I guess it's just a matter of preference.

Page Comments (Click to edit)






[Click to add or edit comments])

Please prepend comments below including a date

Design by N.Design Studio, adapted by solidGone.org (version 1.0.0)
Have a nice day.