PDA

View Full Version : Bash: Howto force line feed AND carriage return in script?



Lampi
May 19th, 2009, 12:18 PM
I do have a bash script with several echo commands called like this:

echo -n "Hello World"

How do I format the echo line to force line feed AND carriage return after each command?

At the moment the echo output looks like this:


Hello World
Hello World
Hello World
Hello World
not what I had in mind...

Can I somehow combine /n oder /r to force line feed and carriage return in scripts or can I use ANSI / escape sequences?

howlingmadhowie
May 19th, 2009, 12:55 PM
why are you passing the -n flag to echo?

ghostdog74
May 19th, 2009, 12:59 PM
use printf

cdenley
May 19th, 2009, 02:51 PM
echo -e "line1\r\nline2"


You shouldn't need a carriage return if the script is run on Linux. Several echo lines wouldn't result in each line being further to the right. If you use the "-n" option, they will all be on one line, though.