Linux Shell Script First Knowledge

Source: Internet
Author: User

Shell Secript:

Differences in execution modes:
The./sh execution is performed in the creation of a subroutine that only inherits the environment variables,
If the export declares that the subroutine's subroutine will inherit, it will not be promoted to an environment variable

Source is executed by placing the script in the context of the parent program,
Where the variable is promoted to an environment variable if export declares


Test judgment, [] judgment is the same, it is recommended to use [] the way of judging
  



Default variables ($, $ ...)

$0, $1.... Positional variables, representing parameter $#: the number of parameters [email protected]: represents the parameter " $" "$ $" "" $4 " $*: stands for "$1c$2c$3c$4", where C is a delimiter, default is blank




Shift: Variable offset
Each time it is executed, the position of the judge moves to the right one


Condition Judgment:
If [Conditional judgment type];then
Content
Fi

&& representative and; | | Represents or
-A: represents and; -O stands for or

If [Conditional judgment type];then
Content
elif [Conditional Judging type];then
Content
Fi


Use case .... ESAC to judge

Case $ variable in
"First variable content")
Program Segment
;;
"Second variable content")
Program Segment
;;
"*")
Exit 1
;;


Esac

Cycle:

While doing done
while [condition]
Do
Program Segment
Done

When the condition is established, the loop is executed, and the failure is stopped.

until [condition]
Do
Program Segment
Done

When the condition is set up, the standing is stopped and not established, then the circulation

For ... done

For Var in con1 Con2 Con3
Do
Program Segment

Done

Numerical processing
for (initial value; limit value; execution Step)
Do
Program Segment
Done


Random numbers and array arrays
Range of values for ${random} [0,32767]
#!/bin/bash
#

E[1]= "AAA"
E[2]= "BBB"
e[3]= "CCC"

En=3

check=$ ((${random} * ${en}/32767 + 1))
echo ${e[${check}]}


function functions:
function fname () {
Program Segment
}

Functions also have positional variables, $0,$1,$2



Debug of Shell Script
Sh:
-N: Do not execute script, only query syntax issues
-V: Output script contents to screen before execution
-X: Displays the script content you are using to the screen

Linux Shell Script First Knowledge

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.