课程: Learning Linux Shell Scripting
今天就学习课程吧!
今天就开通帐号,24,700 门业界名师课程任您挑!
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…
随堂练习,边学边练
下载课堂讲义。学练结合,紧跟进度,轻松巩固知识。