2

Is it possible to do something like this in bash?

output=$(echo hello; sleep 10) &
pid=$!
# run some more commands
wait $pid
echo $output

I would like to run multiple commands in parallel, capturing their output. I'd like to do it in a "clean" way - not writing to temporary files etc.

Sam Brightman
  • 2,831
  • 4
  • 36
  • 38

1 Answers1

3

You can use a named pipe to communicate between parent and child, see man mkfifo for details. Parent can use read command to fetch data from the pipe.

bobah
  • 18,364
  • 2
  • 37
  • 70