Syntax knowledge of shell scripts--Process Control

Source: Internet
Author: User

①if-elif-elif-else-fi

If-fi

' if ($a >); then echo $a; fi ' or ' if [$a-gt];then echo $a; Fi '

If-else-fi

' if ($a =), then echo $a; else echo 30;fi ' or ' if [$a-eq];then echo $a; else echo 30;fi '

If-elif-elif-else-fi

' if ($a >) && (($a =)); then echo $a; elif (($a > 20)) | | ($a =); then echo $[$a +1];else echo ' Sorry '; Fi '

Note: If you enclose the condition in square brackets [], there must be a space between the if and the [,] operand and [,]
> * * * *-gt = * *-EQ >= * * *-ge <= * *-le < * * * * * *-LT

If Judge document properties

' If [-defrwx filename] '-D exists && directory-E exists-F exists && normal file-R readable-W writable-X Executable

②case $a in value1) command;; value2) command;; VALUE3) command;; *) command; Esac

' Read-p ' please input a number: ' A;

Case $[$a%2] in

0)

echo "The number is even!";;

1)

echo "The number is odd!";;

*)

echo "This is impossible!";;

Esac '

③for Cycle

For variable name in loop condition; do command[;] Done

eg

A= ' seq 1 10 ';

For i in $a;d o echo $i;d One or for i in ' seq 1 ';d o echo $i;d One or for I in 1 2 3 4 5;do echo $i;d One

Note: ' seq a b ' denotes a sequence from a to B, e.g. ' SEQ 1 10 ' generates a sequence from 1 to 10

④while Cycle

    while condition; do Command;done

eg

a=10;

While [$a-ge 1];d o

echo $a;

A=$[$-1];

Done

Syntax knowledge of shell scripts--Process Control

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.