[Top][All Lists]

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

Re: mkfifo and tee within a function

From: Eric Blake
Subject: Re: mkfifo and tee within a function
Date: Wed, 6 Dec 2006 16:14:31 +0000 (UTC)
User-agent: Loom/3.14 (http://gmane.org/)

Chet Ramey <chet.ramey <at> case.edu> writes:

> > $>cmd_print () { mkfifo zout ; (tee zout &); cat zout ; rm zout; }
> > $>printf 'hello\n' | cmd_print
> When job control is not active, Posix requires that a command run in the
> background with `&' behave as if its standard input were /dev/null in the
> absence of any explicit redirection.  Bash counts a pipe directly into
> such a command as one such redirection, but not the pipe into the shell
> function.

Actually, POSIX states this:

"The standard input for an asynchronous list, before any explicit redirections 
are performed, shall be considered to be assigned to a file that has the same 
properties as /dev/null. If it is an interactive shell, this need not happen. 
In all cases, explicit redirection of standard input shall override this 

In other words, the presence or absence of job control is not the best criteria 
for whether to do the /dev/null redirection.  The initial /dev/null redirection 
MUST occur in non-interactive shells, even if job control is active.  However, 
for interactive shells, it is still acceptable to use the presence of job 
control as a hook for deciding whether to perform the redirection.

Eric Blake

reply via email to

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