Unix sleep and clear Commands
The sleep command
Use sleep and clear to display output for a specified period of time.
sleep command pauses your script for a specified number of seconds while you do other things.
For example, you could print a message to the screen and then wait for five seconds while your user reads the message. The following command sleeps for 5 seconds.
$ sleep 5
Wait a specified number of seconds before executing another command. Often used in shell scripts. sleep is built in to ksh93.
The GNU/Linux version allows the number to have a suffix: s for seconds (the default), m for minutes, h for hours, and d for days. The value may also be real number, specifying fractional units as well.
clear command clears the screen. This is often used in shell scripts to make the output easier to read. If your script prints out many lines on the screen, your output will be easier to read if you clear the screen first.
You can clear the screen after your output, but you must give your user time to read what you have echoed before it disappears from the screen. Script writers will commonly use
clear to display a short message in a script, as shown below:
$ echo incorrect input, please try again ;
echo command will print the message to the screen and then your
sleep command will do nothing for three seconds while your user reads the message; then the screen will clear. Notice that we used semicolons between commands in the previous example.
This is required whenever you use multiple commands on the same line. The
clear command clears the screen.
The next lesson uses the
grep command to search text from within a script.