zsh-workers
 help / color / mirror / code / Atom feed
* MULTIOS input
@ 2007-06-27 19:40 Dave Yost
  2007-06-29  5:12 ` Bart Schaefer
  2007-06-29 18:34 ` Wayne Davison
  0 siblings, 2 replies; 4+ messages in thread
From: Dave Yost @ 2007-06-27 19:40 UTC (permalink / raw)
  To: zsh-workers

Is this working correctly?  I'm on Mac OS X 10.4.10.

0 298 Z% cat foo
#!/usr/local/packages/zsh/bin/zsh

echo ZSH_VERSION is $ZSH_VERSION

setopt MULTIOS

echo line 2 \
| (
cat <<< 'line 1
' < /dev/fd/0
)
0 299 Z% ./foo
ZSH_VERSION is 4.3.4
line 1

0 300 Z%


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

* Re: MULTIOS input
  2007-06-27 19:40 MULTIOS input Dave Yost
@ 2007-06-29  5:12 ` Bart Schaefer
  2007-06-29 18:34 ` Wayne Davison
  1 sibling, 0 replies; 4+ messages in thread
From: Bart Schaefer @ 2007-06-29  5:12 UTC (permalink / raw)
  To: zsh-workers

On Jun 27, 12:40pm, Dave Yost wrote:
}
} Is this working correctly?  I'm on Mac OS X 10.4.10.

It's not working incorrectly, I guess.

I'm not sure if this is part of your question, but the <<< operator
appends an implicit newline, so the newline you embedded in the
quotes makes two.

/dev/fd/0 refers to the standard input, which is NOT the standard input
of the subshell (the pipe from "echo line 2") -- it's the standard
input of "cat", which (when I try it on linux) is the <<< operator, so
I see "line 1\n\n" twice.

Whether that's what you get on some other OS depends on whether there
really is a /dev/fd/0 or whether zsh is simulating it, and possibly on
whether the I/O buffering is such that you can read the same input from
the /dev/fd device more than once.

 
} 0 298 Z% cat foo
} #!/usr/local/packages/zsh/bin/zsh
} 
} echo ZSH_VERSION is $ZSH_VERSION
} 
} setopt MULTIOS
} 
} echo line 2 \
} | (
} cat <<< 'line 1
} ' < /dev/fd/0
} )
} 0 299 Z% ./foo
} ZSH_VERSION is 4.3.4
} line 1
} 
} 0 300 Z%
}-- End of excerpt from Dave Yost



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

* Re: MULTIOS input
  2007-06-27 19:40 MULTIOS input Dave Yost
  2007-06-29  5:12 ` Bart Schaefer
@ 2007-06-29 18:34 ` Wayne Davison
  2007-06-30  0:20   ` Bart Schaefer
  1 sibling, 1 reply; 4+ messages in thread
From: Wayne Davison @ 2007-06-29 18:34 UTC (permalink / raw)
  To: Dave Yost; +Cc: zsh-workers

On Wed, Jun 27, 2007 at 12:40:33PM -0700, Dave Yost wrote:
> #!/usr/local/packages/zsh/bin/zsh
> echo ZSH_VERSION is $ZSH_VERSION
> setopt MULTIOS
> echo line 2 \
> | (
> cat <<< 'line 1
> ' < /dev/fd/0
> )

This works for me under Linux:

setopt MULTIOS
echo line 2 | (
cat 9<&0 <<< 'line 1' <&9
)

That dups the current fd0 (the pipe) to fd9, and then takes the input
from fd9 after the <<< data.

..wayne..


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

* Re: MULTIOS input
  2007-06-29 18:34 ` Wayne Davison
@ 2007-06-30  0:20   ` Bart Schaefer
  0 siblings, 0 replies; 4+ messages in thread
From: Bart Schaefer @ 2007-06-30  0:20 UTC (permalink / raw)
  To: zsh-workers

On Jun 29, 11:34am, Wayne Davison wrote:
}
} This works for me under Linux:
} 
} setopt MULTIOS
} echo line 2 | (
} cat 9<&0 <<< 'line 1' <&9
} )

This works, too:

echo line 2 | ( cat <<< 'line 1' <<(</dev/fd/0) )

The trick is to force /dev/fd/0 to be opened before <<< changes stdin.
In fact you don't even need to fork the subshell, just use braces:

echo line 2 | { cat <<< 'line 1' <<(</dev/fd/0) }


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

end of thread, other threads:[~2007-06-30  0:20 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-06-27 19:40 MULTIOS input Dave Yost
2007-06-29  5:12 ` Bart Schaefer
2007-06-29 18:34 ` Wayne Davison
2007-06-30  0:20   ` Bart Schaefer

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