The eval Command
- The eval command causes the command line to scan the inputted line twice.
- It will substitute for variables and then scan the line again.
The wait Command
The wait command can be used to force a script to pause its execution of new commands until a background process completes.
Command syntax:
- wait
- Wait until all background processes started by the script complete.
- wait PID ...
- Wait until the listed process(es) complete.
What was that PID?
To retrieve the PID of the last process started in the background, use “$!”.
Using $!
If you want to start three processes (s1, s2, s3) in the background and wait for only s1 & s2, you can use $!.
- ./s1 & start s1 in the background
- pid1=$! save s1 PID to the variable pid1
- ./s2 & start s2 in the background
- pid2=$! save s2 PID to the variable pid2
- ./s3 & start s3 in the background
- wait $pid1 $pid2 now wait until s1 and s2 complete
- ./s4 run s4 after s1 and s2 are finished
Complex Script Dependencies
Sometime you will have a number of scripts that are interdependent in different ways. We will look at a few examples and how to address them in class.