zsh-users
 help / color / mirror / code / Atom feed
* Redirection (<>)
@ 1998-08-07 15:19 Jan Kroken
  1998-08-07 15:52 ` Zefram
  1998-08-07 16:00 ` Owen M. Astley
  0 siblings, 2 replies; 3+ messages in thread
From: Jan Kroken @ 1998-08-07 15:19 UTC (permalink / raw)
  To: zsh-users


>From zsh.info:

`<>WORD'
     Open file WORD for reading and writing as standard input.  If the
     file does not exist then it is created.

and here's what happens when I try to use it.

~/tmp% cat > f         
a b d f
c d c
c c d
e c d
~/tmp% sed "s/c/f/g" <> f
a b d f
f d f
f f d
e f d
~/tmp% cat f
a b d f
c d c
c c d
e c d
~/tmp% 

And my question is; Why does the output from sed go to stdout?

What does <> really mean?

-- 
                                                     -jk


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Redirection (<>)
  1998-08-07 15:19 Redirection (<>) Jan Kroken
@ 1998-08-07 15:52 ` Zefram
  1998-08-07 16:00 ` Owen M. Astley
  1 sibling, 0 replies; 3+ messages in thread
From: Zefram @ 1998-08-07 15:52 UTC (permalink / raw)
  To: Jan Kroken; +Cc: zsh-users

Jan Kroken wrote:
>What does <> really mean?

It does exactly what it says on the tin.  It opens the file for
input and output (mode O_RDWR), attaching it to standard input (file
descriptor 0).  It does absolutely nothing to standard output, or any
other file descriptor.

You could do "<>foo >&0" to make the same file available as standard
output as well, but the standard text utilities would be rather confused
by this.  It's more useful with character devices, where input and output
are largely separate operations, and there's no seek pointer to share.

-zefram


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Redirection (<>)
  1998-08-07 15:19 Redirection (<>) Jan Kroken
  1998-08-07 15:52 ` Zefram
@ 1998-08-07 16:00 ` Owen M. Astley
  1 sibling, 0 replies; 3+ messages in thread
From: Owen M. Astley @ 1998-08-07 16:00 UTC (permalink / raw)
  To: Jan Kroken; +Cc: zsh-users

> >From zsh.info:
> `<>WORD'
>      Open file WORD for reading and writing as standard input.  If the
                                                 ^^^^^^^^^^^^^^
>      file does not exist then it is created.
> 
> and here's what happens when I try to use it.
> 
> ~/tmp% cat > f         
> a b d f
> c d c
> c c d
> e c d
> ~/tmp% sed "s/c/f/g" <> f
> a b d f
> f d f
> f f d
> e f d
> ~/tmp% cat f
> a b d f
> c d c
> c c d
> e c d
> ~/tmp% 
> 
> And my question is; Why does the output from sed go to stdout?
> 
> What does <> really mean?

It means that the file is opened rw as stdin (instead of read-only, as
normal). sed sends its output to stdout.

If you had a program that tried to write to stdin it would normally fail
(presumably), but wouldn't if you used <>.
(Note: I haven't tried this).

Owen



^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~1998-08-07 16:16 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1998-08-07 15:19 Redirection (<>) Jan Kroken
1998-08-07 15:52 ` Zefram
1998-08-07 16:00 ` Owen M. Astley

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).