Shell scripts 6--loops, comparing

Source: Internet
Author: User

For loop

for var in list;

Do

commands, #使用变量 $var

Done

Example

For I in {A.. Z}; do actions; Done

Latter

For ((i=0;i<10;i++))

{

Commands

}

While condition

Do

Commands

Done

Until cycle

Example

x=0;

Until [$x-eq 9];

Do

Let x + +; echo $x;

Done

If comparison statement

if contions;

Then

Commands

If

else if and ELSE statements

if condition;

Then

Commands

else if Conditon;then

Commands

Else

Commands

Fi

Simple usage:

[Condition] && action;

[Condition] | | Action

Arithmetic comparison:
[$var-eq 0]

[$var-ne 0]

Logical AND Logical OR

[$var 1-ne 0-a $var 2-gt 2]

[$var 1-ne 0-o $var 2-gt 2]

Example

  

#!/bin/Bash#filename:compare. SH Fpath="/etc/passwd"ifthen    echofile  exits; Else    Echo does not exists; fi

Shell scripts 6--loops, comparing

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.