help-bash
[Top][All Lists]
Advanced

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

Re: [Help-bash] modifying files in place.


From: Chris Down
Subject: Re: [Help-bash] modifying files in place.
Date: Fri, 31 May 2013 11:03:14 +0800

On 31 May 2013 09:00, John Kearney <address@hidden> wrote:
> Hi all,
>   so I recently came across a new construct (for me) to edit a file in
> place.
> { rm file && awk 'whatever' >file } <file
>
> I'm just wondering how portable is it? This seems to be making use of OS/FS
> specific behavior.

This works because rm unlinks the file from the inode before writing
to that filename again, so it is not clobbered. In Unix, file removal
is handled lazily, and the original file stays readable on standard
input despite this.

This should be portable across POSIX compliant systems.



reply via email to

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