HowtoForge Forums | HowtoForge - Linux Howtos and Tutorials

HowtoForge Forums | HowtoForge - Linux Howtos and Tutorials (http://www.howtoforge.com/forums/index.php)
-   Programming/Scripts (http://www.howtoforge.com/forums/forumdisplay.php?f=7)
-   -   Echo into a file (http://www.howtoforge.com/forums/showthread.php?t=115)

torben 17th June 2005 17:42

Echo into a file
 
I've found 2 slightly different syntaxes for redirecting the output of echo into a file on the shell:

Code:

echo "something" > file
and

Code:

echo "something" >> file
What's the difference between these 2 commands?

jojo 20th June 2005 11:29

Code:

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".

Code:

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:

Code:

line 1
line 2
line 3

Now when you execute the command

Code:

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

Code:

something
When you run

Code:

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

Code:

line 1
line 2
line 3
something

jojo

linutzy 16th August 2005 21:00

>> means append
 
You are just addiing to the file as stated above.

JulietteKlonk 6th January 2010 12:23

thank you for the informative post and keep up the good work!

masterdam79 21st October 2010 08:41

Echo to another server
 
Just wondering how to echo to another (fingerprinted) server?

Code:

echo "something" >> user@server:file
or

Code:

ssh user@server echo "something" >> file
Doesn't seem to work..

Franz 21st October 2010 09:37

use variable:
X_X="echo something >> file"
ssh user@server $X_X


All times are GMT +2. The time now is 22:19.

Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2014, vBulletin Solutions, Inc.