LINUX study notes 5-SHELL parser

Source: Internet
Author: User

A) Role: Convert user-input commands into programs that can be run on the corresponding machine. It is convenient to repeatedly enter the same command.

 

B) script file: It means the program.

 

C) create a shell script file

 

1. directly open the file with vi, and the file name suffix is. sh.

 

2 .#! /Bin/sh :#! Specifies the parsing program of the script file.

 

3. chmod + x filename: Make it executable

 

4. Use:. File Name

 

D) Note:, a sentence starting with # represents a comment.

 

E) variable:

 

1. No definition is required. assign a value directly: a = "hello world", and "=". No space is allowed between the left and right sides.

 

2. Use the variable $ a, $ {num} nd, and add parentheses to prevent confusion.

 

3. Default variables:

 

A) $ #: Number of command line parameters for the input script

 

B) $ *: all command line parameter values, with spaces between each parameter value

 

C) $0: Command itself (shell file name)

 

D) $1: The First Command Line Parameter

 

E) $2: The second command line parameter

 

4. local variable: add the local keyword local hello = "var2" when the variable is assigned a value for the first time"

 

F) system functions:

 

1. Output: echo

 

G) cyclic structure

 

1. Note 1: There must be spaces around the brackets,

 

2. Note 2: There must be spaces around the comparison character.

 

3. If statement

 

A) if [expression]

 

B) then

 

C) # code block

 

I. else if [expression] Abbreviation: elif

 

Ii. then

 

Iii. # code block

 

Iv. else

 

V. # code block

 

Vi. Fi

 

D) Fi

 

4. For Loop

 

A) for var in [list] The variable var does not contain the "$" symbol.

 

B) do

 

C) # code block

 

D) Done

 

5. while Loop

 

A) while [condition] is executed when true

 

B) do

 

C) # code block

 

D) Done

 

6. until Loop

 

A) until [condition] is executed when it is false.

 

B) do

 

C) # code block

 

D) Done

 

7. Case statement

 

A) case "$ var" in

 

B) condition1)

 

C); equivalent to break

 

D) condition2)

 

E );;

 

F) *) default statments; equivalent to the default Condition

 

G) esac

 

H) comparison:

 

1. Compare operations integer operations string operations

 

2. Same-eq =

 

3. Different-ne! =

 

4. Greater than-gt>

 

5. Less than-lt <

 

6. greater than or equal to-ge

 

7. less than or equal to-le

 

8. Blank-z

 

9. Not blank-n

 

10. There are spaces on the left and right sides of the "[" and "]" symbols.

 

11. There are spaces around "="

 

I) judgment:

 

1. The-e file already exists.

 

2. The-f file is a common file.

 

3.-s file size is not zero

 

4. The-d file is a directory

 

5. The-r file can be read by the current user.

 

6. The-w file can be written to the current user.

 

7. The-x file can be executed on the current user

 

From the column of ainemo

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.