Linux Advanced Bash Programming (Process Control-while,break,continue)

Source: Internet
Author: User

In bash programming, it often involves using while statements to deal with the number of unknown loops at times.

    1. While syntax

While [Express]do#commanddone

2. Practical Practice

    • Prompt to enter an integer greater than 10 less than 20;

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 "/>

    • Guess the number, guessed the end;

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 "/>

    • control while using parameters that are brought in when the script is executed

While3.sh:#!/bin/bashn=$1while [-N "$n"] ["$n"-GT 0]doecho-n "*" Let N--done-------------------------$bash while3. SH 5$*****
    • About the use of break and continue. The keyword "break" is used to jump out of the loop, and the keyword "continue" is used to skip to the next loop without executing the rest of the section.

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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.