Hello!
Command
itself hangs up because FIFO must be opened for reading and writing simultaneously. You can use
instead, but in this case one can not close only one end of FIFO because both ends are the same. Here is an example:
Code:
#!/bin/bash
rm /tmp/fifo
mkfifo /tmp/fifo
exec 8<> /tmp/fifo
echo fifocontent >&8 &
cat <&8
This script do the work, but hangs up on last command (`cat') because write-end of FIFO (fd 8) not closed (as well as read-end fd=8).
P.S.: putting exec in background can't help because new file descriptor is accessible in subshell only (I think). Following script exhibits this behaviour:
Code:
#!/bin/bash
exec 3>&1 &
echo "test-message" >&3 # fd 3 is unaccessible if
# we use subshell (&) in
# previous line
This script will work if we delete &-sign at the tail of second line.
One can use following approach, though:
Code:
#!/bin/bash
rm /tmp/fifo
mkfifo /tmp/fifo
(exec 9> /tmp/fifo; echo fifocontent >&9)&
(exec 8< /tmp/fifo; cat <&8) &
exit 0;