课程: Learning Linux Shell Scripting
今天就学习课程吧!
今天就开通帐号,24,700 门业界名师课程任您挑!
The while loop
- [Instructor] Loops give us the ability to execute our code repetitively. We have two loop statements, while and for. Let's begin with the while loop. In the terminal type touch while and then we're gonna do a change mode while.sh and finally, atom while.sh. We'll add the shebang. And we'll give ourselves a counter which will hold the count of the passes through the loop. Count equals zero. Now, the while loops is structured similar to the if statement. So, we're gonna say while count and we need the dollar sign count is less than and we'll make it 10. It begins with a test which is evaluated at the top of each loop. If true, the commands between the do and the done statements are executed. So, we've got a do, and a done and then in between we're gonna say echo count equals #COUNT and count++. Here we display the value of the count variable and increment it by one each pass through the loop. Then it returns to the top of the loop and evaluates again. If the test fails, it exits the…
随堂练习,边学边练
下载课堂讲义。学练结合,紧跟进度,轻松巩固知识。