In a shell script, I am trying to start a background command that has the same stdin as that of the shell script.
#!/bin/sh
# ...
the-program &
However, the-program
above will not have access to the same standard input as that of the shell script. According to my shell's manual (dash(1)):
If the shell is not interactive, the standard input of an asynchronous command is set to
/dev/null
.
I have tried the-program & <&0
but it does not seem to have the intended effect; the standard input of the-program
is still /dev/null
.
I thought about creating a new file descriptor by duplicating the standard input of the shell script and somehow pass that new file descriptor to the background process. However, the background process must then somehow redirect that new file descriptor to its standard input (replacing /dev/null
). I have no idea if this idea is even possible, and I do not know how to implement it in POSIX sh.