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: Dan Douglas
Subject: Re: [Help-bash] Quick prepend to file using echo
Date: Fri, 18 May 2012 18:24:49 -0500
User-agent: KMail/4.8.3 (Linux/3.3.4-pf+; KDE/4.8.3; x86_64; ; )

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� 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. 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. GNU's
ed is really not that bad to work with.
--
Dan Douglas

Attachment: signature.asc
Description: This is a digitally signed message part.


reply via email to

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