From the course: Learning Linux Shell Scripting

Unlock the full course today

Join today to access over 24,800 courses taught by industry experts.

Using the sleep command

Using the sleep command

- [instructor] Some processes only need to run intermittently. You can use the sleep command to have them go to sleep until they are needed. From the terminal, we're gonna say touch delay.sh, chmod 755 delay.sh, and atom delay.sh. Begin with our ever-present #!/usr/bin/env bash, then we're gonna create a variable to hold the time for our delay, how long we want our script to go to sleep, so we'll say DELAY=$1, then we're gonna do an if. Now, what we're gonna do here is we're gonna check to make sure that we got some input, 'cause without input this script won't work. We're gonna say, -z $DELAY. This is just gonna make sure that DELAY has a value, because if it doesn't, and that's what the -z is for, then what we're gonna do is say, then echo "You must supply a delay" and then exit. And, this time, we're gonna use an exit 1 to indicate there was some sort of an error. Then, we'll have a fi to close off our if statement. Then, we're gonna let the user know what's gonna happen next, and…

Contents