zsh-workers
 help / color / mirror / code / Atom feed
From: Eric Blake <eblake@redhat.com>
To: David Korn <dgk@research.att.com>, austin-group-l@opengroup.org
Cc: Bash - Bug <bug-bash@gnu.org>,
	zsh-workers@zsh.org, dash <dash@vger.kernel.org>,
	miros-discuss@mirbsd.org
Subject: '>;' redirection operator [was: [1003.1(2008)/Issue 7 0000530]: Support in-place editing in sed  (-iEXTENSION)]
Date: Thu, 22 Dec 2011 14:03:26 -0700	[thread overview]
Message-ID: <4EF39B1E.80709@redhat.com> (raw)
In-Reply-To: <201112221539.pBMFdlaj011933@penguin.research.att.com>

[-- Attachment #1: Type: text/plain, Size: 2100 bytes --]

[cc'ing bash, dash, mksh, and zsh developers; feel free to avoid
cross-posted replies on content not relevant to all the groups]

On 12/22/2011 08:39 AM, David Korn wrote:
> Subject: Re: Re: [1003.1(2008)/Issue 7 0000530]: Support in-place editing in sed  (-iEXTENSION)
> --------
> 
> There are many commands other than sed that want the output to replace
> an input file.  That is why I added the >; redirection operator to ksh93.
> 
> With >; you can do
> 	sed -e s/foo/bar/ file >; file
> to do in place sed.  The >; operator generates the output in a temporary file
> and moves the file to the original file only if the command terminates
> with 0 exit status.

I agree that engineering a single fix into the shell that can apply to
multiple situations, rather than chasing down a set of applications to
add an in-place editing option to each, is a much more flexible and
powerful approach.  Can we get buy-in from other shell developers to
support '>;' as an atomic temp-file replacement-on-success idiom, if
POSIX were to standardize the existing practice of ksh93 as the basis?

I assume on the ksh implementation that the temp file is discarded if
the command (simple or compound) feeding the redirection failed?  If the
redirection is used on a simple command, is there any shorthand for
specifying that the destination name on success also be fed as an
argument to the command, to avoid the redundancy of having to type
'file' both before and after the '>;' operator?  I assume that this is
like any other redirection operator, where an optional fd number can be
prepended, as in '2>; file' to collect stderr and overwrite file on
success?  What happens if there is more than one '>;' redirection in the
same command, and both target the same end file (whether or not by the
same file name)?  What happens if the command succeeds, but the rename
of the temp file to the destination fails?  Are there clobber ('>|') or
append ('>>') variants?

-- 
Eric Blake   eblake@redhat.com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 620 bytes --]

       reply	other threads:[~2011-12-22 21:19 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <201112221539.pBMFdlaj011933@penguin.research.att.com>
2011-12-22 21:03 ` Eric Blake [this message]
2011-12-22 22:09   ` Bruce Korb
2011-12-22 23:34     ` '>;' redirection operator Thorsten Glaser
2011-12-23  0:14     ` '>;' redirection operator [was: [1003.1(2008)/Issue 7 0000530]: Support in-place editing in sed (-iEXTENSION)] Geir Hauge

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4EF39B1E.80709@redhat.com \
    --to=eblake@redhat.com \
    --cc=austin-group-l@opengroup.org \
    --cc=bug-bash@gnu.org \
    --cc=dash@vger.kernel.org \
    --cc=dgk@research.att.com \
    --cc=miros-discuss@mirbsd.org \
    --cc=zsh-workers@zsh.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).