Size: 750
Comment: replacing subshell with grouping according to pgas's suggestion
|
Size: 749
Comment:
|
Deletions are marked like this. | Additions are marked like this. |
Line 11: | Line 11: |
If the commands are consecutive, they can be grouped and redirect it's output: | If the commands are consecutive, they can be grouped and redirect its output: |
How to write several times to a fifo without having to reopen it?
The basic use of named pipes is:
cat < myfifo & echo 'a' > myfifo
this works but, cat dies after it. What if we want to write several times to the pipe without having to reopen it?
If the commands are consecutive, they can be grouped and redirect its output:
cat < myfifo & { echo 'a'; echo 'b'; echo 'c'; } > myfifo
But if they can't be grouped for some reason, a better way is to assign a file descriptor to the pipe and write there:
cat < myfifo & # assigning fd 3 to the pipe exec 3>myfifo # writing to fd 3 instead of the pipe echo 'a' >&3 echo 'b' >&3 echo 'c' >&3 # closing the fd exec 3>&-