[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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

From: Stephane Chazelas
Subject: Re: substitution "read all from fd" silently fails: $(<&0)
Date: Thu, 2 Jul 2015 09:49:13 +0100
User-agent: Mutt/1.5.21 (2010-09-15)

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

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

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


reply via email to

[Prev in Thread] Current Thread [Next in Thread]