0

This doesn't work:

   $ head file | tee >(sort >&3) | paste <(cat <&3) -
   bash: 3: Bad file descriptor

but I hope it's obvious what it's intended to do, the equivalent of:

   $ head file | sort >temp1
   $ head file >temp2
   $ paste temp1 temp2

What is the proper way to create and use that parallel pipe?

(Assume "head" represents an expensive operation, and I'm aware of the dangers of deadlock.)

Kamil Maciorowski
  • 69,815
  • 22
  • 136
  • 202
Ray
  • 3
  • 1
  • Possible duplicate of [Piping with Process substitution and joining output again](https://superuser.com/questions/1194044/piping-with-process-substitution-and-joining-output-again) – Kamil Maciorowski Feb 02 '18 at 17:58

1 Answers1

0

I've found that explicitly creating another pipe first does what I wanted to do:

$ pipe3="$$.pipe3"
$ mkfifo $pipe3
...
$ head file_1 | tee >(sort >$pipe3) | (sleep 1; paste <(cat <$pipe3) - )
...
$ tail file_2 | tee >(sort -r >$pipe3) | (sleep 1; paste <(cat <$pipe3) - )
...
$ rm $pipe3

The need for "sleep", and using "$pipe3" rather than "&3", makes it a bit less elegant though.

Ray
  • 3
  • 1