The following code:
#!/bin/bash -x
mkfifo pipe 2>/dev/null
tee pipe >/dev/null &
cat pipe
produces no output when run as follows:
$ echo "hi" | ./test.sh
+ mkfifo pipe
+ cat pipe
+ tee pipe
$
Why?! I would expect tee to copy stdin to the named pipe (and /dev/null), and then cat to copy the contents of the named pipe to stdout. Why doesn’t it work?!
I’m trying to write a bigger bash script and I really need the tee in there, with something else in the place of /dev/null. I narrowed down the unexpected behaviour to the example above.
when you background a process its standard input will be set to
/dev/nullSo you need to specify you want the
stdinof the parent, in your case the pipe betweenechoand./test.sh