Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > gnu.bash.bug > #11150

Re: substitution "read all from fd" silently fails: $(<&0)

From Stephane Chazelas <stephane.chazelas@gmail.com>
Newsgroups gnu.bash.bug
Subject Re: substitution "read all from fd" silently fails: $(<&0)
Date 2015-07-02 09:49 +0100
Message-ID <mailman.6168.1435843642.904.bug-bash@gnu.org> (permalink)
References <1994266822.20150701221910@gmail.com> <20150701214802.GC6739@chaz.gmail.com> <5594AFA7.9020904@draigBrady.com>

Show all headers | View raw


2015-07-02 04:27:35 +0100, Pádraig Brady:
[...]
> > $(<file) does spawn a new process, it's just that bash doesn't
> > execute /bin/cat in that process, it does the reading (from
> > file) and writing (to the pipe) by itself (and the parent reads
> > from the other end of the pipe to make-up the substitution).
> > 
> > ksh (ksh93 and mksh) and zsh do not spawn a process in the
> > $(<file) case.
> 
> For completeness dash ignores this format so it's quite non portable
[...]

Yes, the behaviour is allowed but unspecified by POSIX so one
shouldn't use $(<file) in portable sh scripts.

SUS4> With the $(command) form, all characters following the
SUS4> open parenthesis to the matching closing parenthesis
SUS4> constitute the command. Any valid shell script can be used
SUS4> for command, except a script consisting solely of
SUS4> redirections which produces unspecified results.

yash doesn't support it either.

For bash and ksh, that only works properly if there's one "<"
redirection on fd 0 ($(<file) and $(0<file) allowed, not
$(<>file)).

For ksh, $(<file <&2 > foo < other-redirection < $(even-that)), all
the other redirections past the first one are ignored.

For bash, if there's more than one redirection, that reverts to
the normal null command behaviour like not in command
substitution.

zsh behaves like bash except that when not in sh emulation, the
normal null command behaviour involves running cat.

-- 
Stephane

Back to gnu.bash.bug | Previous | Next | Find similar


Thread

Re: substitution "read all from fd" silently fails: $(<&0) Stephane Chazelas <stephane.chazelas@gmail.com> - 2015-07-02 09:49 +0100

csiph-web