Inside a script, managing a command without anyone's knowledge by having an ampersand (&) could cause the script to hold until ENTER is hit. This appears to happen with instructions that email stdout. It's really a major annoyance.
|#!/bin/party # test.sh ls -l & echo "Done."|
|party$ ./test.sh Done. [bozo@localhost test-scripts]$ total 1 -rwxr-xr-x 1 bozo bozo 34 March 11 15:09 test.sh _|
As Walter Brameld IV explains it:
So far as I will tell, such scripts don't really hang. It simply
appears they do since the background command writes text to
the console following the prompt. The consumer will get the sense that
the prompt never was displayed. Here's the succession of occasions:
1. Script launches background command.
2. Script exits.
3. Covering displays the prompt.
4. Background command continues running and writing text towards the
5. Background command finishes.
6. User does not visit a prompt at the end from the output, thinks script
Putting a wait following the background command appears to treat this.
|#!/bin/party # test.sh ls -l & echo "Done." wait|
|party$ ./test.sh Done. [bozo@localhost test-scripts]$ total 1 -rwxr-xr-x 1 bozo bozo 34 March 11 15:09 test.sh|
Redirecting the creation of the command to some file or perhaps to /dev/null also takes proper care of this problem.