views:

63

answers:

4

For Ex :

echo "adsa " >> a.txt
echo "asdad " >> a.txt

in my file

adsa
asdad

But i am looking for

adsa asdad 
+5  A: 

Some platforms support echo -n to suppress printing newline... man echo might help

jowierun
It's more a matter of which shell than which platform (and on some shells it's a matter of whether the relevant option is on). `man echo` is not so much help because it might not warn about the portability issue. [`printf`](http://stackoverflow.com/questions/3424193/how-stop-to-going-to-new-line-in-shell-script/3424781#3424781) is the way to go.
Gilles
I agree. If you want portability, printf is it.
fpmurphy
+2  A: 

From echo manpage:

-n do not output the trailing newline

Ethan Shepherd
+2  A: 

Specifically, bash (from OP's tag) has a builtin echowhich supports -n. Try help echo from bash to see the help for the builtin command

Luther Blissett
+5  A: 

You can also use printf:

printf "adsa " >> a.txt
printf "asdad " >> a.txt
printf "\n" >> a.txt

or

printf "adsa " >> a.txt
printf "asdad \n" >> a.txt
Dennis Williamson