Shell Process Control

Source: Internet
Author: User

  If statement

The judging condition is wrapped up in []

If [$a > $b]

Then

Echo ' a > B '

elif [$a < $b]

Then

Echo ' A < b '

Else

Echo ' A==b '

Fi

  

for Statement

Iterating through an array

For arr in ${array[*]}

Do

Echo ${arr}

Done

while Statement

If the value of the variable is less than 5, then the value of the variable plus 1 output

Var=1

While [$var –lt 5]

Do

var= ' Expr $var +1 '

Echo $var

Done

Defining functions

  Some functions are reusable, can be encapsulated into functions, the function is defined in the following format:

Function_name () {

List of commands

[Return value]

}

  Calling functions

The pass-through parameter is optional. If you need to pass a parameter, simply add the argument value after the called function

Function_name 10 20

  Get the value of a parameter in a function

  When defining a function, the arguments in parentheses after the function name are not written, to get the parameters passed in the function using $

Get first parameter

$ get second argument

Get the return value of a function

$? is to get the result returned by the previous instruction, then to get the value returned by the function, just write the $ on the line below the statement that called the function.

Shell 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.