From: "Bart Schaefer" <schaefer@candle.brasslantern.com>
To: zsh-workers@sunsite.dk
Subject: Re: <> redirection operator
Date: Sun, 3 Jun 2001 23:06:35 +0000 [thread overview]
Message-ID: <1010603230636.ZM30691@candle.brasslantern.com> (raw)
In-Reply-To: <20010603231405.92A4614285@pwstephenson.fsnet.co.uk>
On Jun 4, 12:14am, Peter Stephenson wrote:
}
} % echo test >/tmp/redirtest
} % sed 's/e/Z/g' <>/tmp/redirtest 1>&0
} % cat /tmp/redirtest
} tZst
}
} (This happens to work in place even on a mult-line file, but I think you
} have to be pretty sure what you're doing to use it like that. Finally I've
} got an example of this for the user guide, anyway.)
I gave an example of using <> a few months ago ... let's see ... ah, here it
is, sent to zsh-users in December:
------------
Yes, <> means "open for both reading and writing," which is sometimes
useful as it's the mode in which stdin/out/err are typically opened on
a terminal. The implicit descriptor to the left of <> is 0, so unless
you supply another number it opens stdin.
If you give a descriptor number, you can use <> to open a file for
overwrite-without-truncation:
zsh% print "foo\nbar" >| foo
zsh% <foo
foo
bar
zsh% print xxx 1<>foo
zsh% <foo
xxx
bar
So if you know that e.g. sed is either going to fail to produce any output
at all, or will succeed with exactly as much output as the length of the
original input, you can do
sed 's/foo/bar/g' <foo 1<>foo
But this is pretty dangerous because if sed ever writes more bytes than it
has already read, it'll start re-reading what it wrote.
--
Bart Schaefer Brass Lantern Enterprises
http://www.well.com/user/barts http://www.brasslantern.com
Zsh: http://www.zsh.org | PHPerl Project: http://phperl.sourceforge.net
next prev parent reply other threads:[~2001-06-03 23:07 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2001-06-03 20:10 Clint Adams
2001-06-03 20:49 ` Bart Schaefer
2001-06-03 21:00 ` Clint Adams
2001-06-03 23:14 ` Peter Stephenson
2001-06-03 23:06 ` Bart Schaefer [this message]
[not found] <201112221539.pBMFdlaj011933@penguin.research.att.com>
2011-12-22 21:03 ` '>;' redirection operator [was: [1003.1(2008)/Issue 7 0000530]: Support in-place editing in sed (-iEXTENSION)] Eric Blake
2011-12-22 22:09 ` Bruce Korb
2011-12-22 23:34 ` '>;' redirection operator Thorsten Glaser
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=1010603230636.ZM30691@candle.brasslantern.com \
--to=schaefer@candle.brasslantern.com \
--cc=zsh-workers@sunsite.dk \
/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).