Echo into a file

Discussion in 'Programming/Scripts' started by torben, Jun 17, 2005.

Thread Status:
Not open for further replies.
  1. torben

    torben New Member

    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?
     
    rahama likes this.
  2. jojo

    jojo New Member HowtoForge Supporter

    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
     
  3. linutzy

    linutzy New Member

    >> means append

    You are just addiing to the file as stated above.
     
  4. JulietteKlonk

    JulietteKlonk New Member

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

    masterdam79 New Member

    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..
     
  6. Franz

    Franz Member

    use variable:
    X_X="echo something >> file"
    ssh user@server $X_X
     
Thread Status:
Not open for further replies.

Share This Page