1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2012
    Rep Power

    Question: writing to a file

    I had a quick question. Is there a differnce between

    echo $$ >somefile.txt


    echo $$ >> somefile.txt
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Jun 2012
    Rep Power
    The first syntax (with 1 >) will destroy any existing file having that name before writing to it. The second one (with >>) will append whatever you write to the existing content of the file.
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Apr 2009
    Rep Power
    According to your posting history, all of your questions have been related to shell scripting, not Perl. Shell script questions are best asked in the Linux or UNIX topic areas.
    Linux Help
    UNIX Help

    The focus of your question here is not language specific, so it's not much of a faux pas.

    The > redirection operator will send the output to somefile.txt overwriting the file if it already existed, or creating it if it didn't exist.

    The >> operator will append the output to the end somefile.txt, creating the file if it didn't already exist.

IMN logo majestic logo threadwatch logo seochat tools logo