Linux Bash Shell Learning (13): Process Control -- while/util

Source: Internet
Author: User

This article is also the fifth chapter of "Learning the bash Shell" 3rd Edition, five of Flow Control's reading notes, but we will not limit it to this. Flow control is a common part of any programming language, including while and util, which are also common in advanced programming languages. Here, we will continue to learn about them.

The while and util syntaxes are the same, as follows:

While
|Util
Condition;
Do

Statements
...
Done

Like if, condition may consist of a series of statements whose value is the exit status of the final statment. The while and until conditions are just the same. The while check conditions are executed when they are true, while the until conditions are false. Unlike C, util sticks to the condition from the beginning, rather than at the end of each loop. If you add "! ", While and util are actually no different, but until is a bit interesting in the following situation:

Until
Command
;Do

Statements
...
Done

Execute statements until the command runs correctly.

Until cp $1 $2; do

Echo 'attempt to copy failed. waiting ...'

Sleep 5

Done

For example, in the above example, try the copy command every five seconds until the copy is successful. You can also use the while! Cp $1 $2; do... method.

Add the bash shell script with the suffix sh, so that different colors can be displayed in gedit compilation, which is more convenient.

Related links:
My articles on Linux operations

 

Related Article

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.