Linux Learning Note 2015-12-09

Source: Internet
Author: User


The beginning of the script needs to use #!/bin/bash to start the script, in the script, it is best to use the # comment comments, develop good habits

In the system, the default is a variable reply variable

In declare you can define the type of a variable

Declare-i a------defines a as integral type

You can use echo $ to find the return value, the correct command return value is 0, the wrong return positive value

In Linux, you can use test to compare values.

The syntax is: Test $AA-lt $BB--------to determine that the AA variable is less than the BB variable

You can also use the [] bracket to compare

The syntax is: [$AA-gt $BB]-----Represents the contrast of the variable AA greater than the variable BB. If it is true

Returns 0, error returns non 0 positive

Judging 1 && Judging 2--------"and" connectors must be true on both sides before returning

If the judge 1 is false, then do not go to Judge 2, return False

Summary:&& must be true for 2 sides, then return True

Judgment 1 | | Judge 2--------"or" connector, as long as one side is true, the execution returns to True

If Judge 1 is false, proceed to judgment 2 and Judge 2 as true

will return to the true

Summary: | | One side is true, it returns true

Conditional Judgment Statement

Grammar:

if Judgment statement; Then

Command

Elif judgment statement; then

Command

Else

Command

Fi


eg

#!/bin/bash

grep ^$1/etc/passwd

If ["$?"-eq 0];then

echo "This account exists"

Else

echo "This account does not exist"

Fi

Example 2:

#!/bin/bash

echo "Please enter your Age:"

Read name

If [$name-lt 0] | | [$name-gt];then

echo "Please enter the correct age"

elif [$name-le];then

echo "Hello, young man"

elif [$name-le];then

echo "Hello, middle-aged"

Else

echo "Hello, Old man"

Fi

Define a functional function

Grammar

function Test () {

echo "This is a function"

}

Test #直接用函数名即可调用执行此函数


Cycle

While [judgment statement]------conditions until the end loop is not established

Do

Command

Done

Until [judgment statement]---------condition is not established until the condition is set to the end of the cycle

Do

Command

Done



For loop

For XX in value 1 value 2 value 3 .....

Do

Command


Done


Linux Learning Note 2015-12-09

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.