help-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Help-bash] Quick prepend to file using echo


From: Chris Jones
Subject: [Help-bash] Quick prepend to file using echo
Date: Wed, 16 May 2012 19:16:03 -0400
User-agent: Mutt/1.5.20 (2009-06-14)

Using ‘echo’, it's easy to append to a file:

--------------------------------------------------------------------------------
$ echo "// vim: set tw=80 syntax=sh:" >> ~/.bashrc
--------------------------------------------------------------------------------

But how do you do it the other way around..? Prepend to a file so-to-speak..? 

I saw a couple of threads in stackoverflow.com with complicated one-liners and
everybody appeared to conclude that you need a temp file anyway..

So how about:

--------------------------------------------------------------------------------
$ echo -e "$(echo -e "// vim: set tw=80 syntax=sh: ";cat ~/.bashrc)" > ~/.bashrc
--------------------------------------------------------------------------------

- how does it work..? Namely why isn't the file overwritten..?
- barring a power failure while running.. could this cause data loss..?
- is there a portable way to do it with printf..?

Just curious.. Even for one character, I would fire up an editor.

CJ

-- 
Focus follow mouse users will burn in hell!!!




reply via email to

[Prev in Thread] Current Thread [Next in Thread]