PDA

View Full Version : Echo into a file


torben
17th June 2005, 18:42
I've found 2 slightly different syntaxes for redirecting the output of echo into a file on the shell:

echo "something" > file

and

echo "something" >> file

What's the difference between these 2 commands?

jojo
20th June 2005, 12:29
echo "something" > file
means that everything that's in "file" will be deleted, and "something" will be written to it (which means that "something" will be right at the beginning of "file".

echo "something" >> file
means that "something" will be appended to "file", so nothing will be deleted from "file", and "something will be at the end of "file".

"file" will be created if it doesn't exist in both cases.

A little example:

We have the file "file" with the following contents:

line 1
line 2
line 3

Now when you execute the command

echo "something" > file

the content of "file" will be

something

When you run

echo "something" >> file
instead, the content of "file" will be

line 1
line 2
line 3
something

jojo

linutzy
16th August 2005, 22:00
You are just addiing to the file as stated above.