In a background process, stdin defaults to /dev/null, so we need to do
a little dance. <&0 looks like it ought to work according to the bash
manual and does indeed work in bash, but not in dash. This
construction seems to work in both.
Tested with:
date | sh -exc 'cat <&0 >t &'
SuS says:
If job control is disabled (see set, -m), 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. This shall not happen if job control is
enabled. In all cases, explicit redirection of standard input shall
override this activity.
Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
set fakeuh [open $fakeuf w 0755]
puts $fakeuh "#!/bin/sh
set -e
-cat >$pipefp.r &
+exec 3<&0
+cat <&3 3<&- >$pipefp.r &
exec 3<>$pipefp.t
exec <$pipefp.t
exec 3<&-