help-bash
[Top][All Lists]
Advanced

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

Re: [Help-bash] Quick prepend to file using echo


From: clark wang
Subject: Re: [Help-bash] Quick prepend to file using echo
Date: Sat, 19 May 2012 20:05:14 +0800

On Sat, May 19, 2012 at 7:24 AM, Dan Douglas <address@hidden> wrote:
On Wednesday, May 16, 2012 07:16:03 PM Chris Jones wrote:
> 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..

People are quick to jump to tmp files and GNU sed -i.

sed -i (and ksh93's >; operator) does not work well with symlinks.
 
This shouldn't be
recommended before first ruling out ed (or ex). Short of moving to a different
scripting language, a real editor is still the only sane way to modify a file
"in-place" from a shell script. sed -i is a hack. Some use it if some sed
feature specifically makes the job easier, though I suspect the real reason is
almost always because they don't want to have to learn something else.

It's true for me. I'm planning to learn ed soon. :)
 
GNU's
ed is really not that bad to work with.
--
Dan Douglas


reply via email to

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