In bash programming, it often involves using while statements to deal with the number of unknown loops at times.
While syntax
While [Express]do#commanddone
2. Practical Practice
While1.sh:#!/bin/bashecho-n "Please input a digit between:" Read Nwhile [$n-lt 10]| | [$n-gt]doecho-n "Please input a digit between and:" Read Ndoneecho "Your digit is $n, thank you!"
650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M00/7F/78/wKiom1cfW--QKLWJAABbhCjvpK0745.jpg "title=" While1 . JPG "alt=" Wkiom1cfw--qklwjaabbhcjvpk0745.jpg "/>
While2.sh:#!/bin/bashecho-n "Please guess a number between 0 and ten:" Read Nwhile [$n-ne 8]doecho-n "Please guess Agai N (0-10): "Read Ndoneecho" Congratulation,you guessed! The lucky number is 8! "
650) this.width=650; "src=" http://s1.51cto.com/wyfs02/M01/7F/78/wKiom1cfcqvSxhQ9AABu_SJbmu0311.jpg "title=" While2 . JPG "alt=" Wkiom1cfcqvsxhq9aabu_sjbmu0311.jpg "/>
While3.sh:#!/bin/bashn=$1while [-N "$n"] ["$n"-GT 0]doecho-n "*" Let N--done-------------------------$bash while3. SH 5$*****
While4.sh:#!/bin/bashn=$1while [-N $n]do if [$n-eq 0]then echo-e "" Breakelse echo-n "*" Let n--continue Fidone execution: $bash while4.sh 5*****
This article is from the "Reminder Flower Rain" blog, please make sure to keep this source http://chenwen.blog.51cto.com/771416/1768050
Linux Advanced Bash Programming (Process Control-while,break,continue)