1

From the command line, typing cat waits for user input. But in the following script, wait ignores the background process.

#!/bin/bash
cat &
wait
echo "After wait"

This script immediately blasts right past the wait command. How can I make wait actually wait for the cat command to finish? I've tried waiting for the specific PID or job number, but the effect is the same.

Charles Duffy
  • 280,126
  • 43
  • 390
  • 441
ishmael
  • 1,796
  • 3
  • 18
  • 19

1 Answers1

3

That's because cat is exiting right away, because stdin is not inherited. Try this instead:

cat <&0 &
vanza
  • 9,715
  • 2
  • 31
  • 34