September 13, Bash summary

Source: Internet
Author: User
Tags terminates

Bash is written on a command program file that is called on the machine.

External commands are provided by each application

Program is by: instruction (algorithm) + data (structure)

Process oriented

Command-centric, design algorithms, data services to algorithms

Object oriented

Data-centric, design structure, program services

Bash's Process Control statement:

Sequential execution: Execute one by one

Select execution: Select one of the multiple bars by criteria to execute

Cyclic execution: Number of executions by condition

Variable: The memory space of the name after the program is run, can be called repeatedly modify

Local variable: The current shell process is valid.

Environment variable: exists in both the current shell process and its child processes. Local variables that are exported

Local variables: Existing during the execution of a function.

Positional parameter variables: parameters passed to the script in the script,

Special variables:

$? (Previous command execution result), 0 is true, 1-255-bit false

$*(),

[Email protected] (),

$#(),

$$()

The value type of the variable:

Values: Shaping and floating-point

Character: ASCII

Bash is a character-type, weakly-typed, and does not need to be declared beforehand.

The following can declare a variable as an integer type

Declare–i name=5

Let Name=5

Single quote: Strong reference, and its internal variables keep the original characters

Double quotes: Weak references, whose internal variables are replaced with variable values

Command reference: ' Command ', $ (command), the execution result of the reference command

Naming method:

Local variables

Variable name = variable value, default is character type

Environment variables:

Export variable Name

Declare–x variable Name

View: Env,printent,export

650) this.width=650; "title=" image "style=" border-right-width:0px;border-bottom-width:0px;border-top-width:0px; " Border= "0" alt= "image" Src= "http://s3.51cto.com/wyfs02/M01/73/75/wKiom1X-qiPSyOtwAABh06ZS_4w329.jpg" width= "458" Height= "/>"

Life cycle:

Automatic destruction: Shell process termination is destroyed

Manual destroy: unset variable name

Script: is a text file that is executed by bash to read from.

Startup script:

1,bash Pin Name

2, give the Execute permission pin name first

Shebang syntax format: First line write #!/bin/bash, interpreter path

Note: #内容

The custom status result exit 5 terminates the current process.

Sometimes we just want state results, we don't want state content, so we're going to discard the results.

/dev/null will swallow all the incoming data and discard it.

/dev/zero will swallow the data and spit out a bunch of 0.

To test an expression:

An 1,test expression.

650) this.width=650; "title=" image "style=" border-right-width:0px;border-bottom-width:0px;border-top-width:0px; " Border= "0" alt= "image" Src= "http://s3.51cto.com/wyfs02/M02/73/75/wKiom1X-qiPDExLLAAA0dY3yxQQ817.jpg" width= "244" Height= "/>"

2, the expression should look like this [expression], if there is no space between the parentheses will be an error.

It can also be written as [[expression]], which is called a keyword.

The following are the parameters of the above command

Integer test:

-GT: Greater Than

-ge: greater than or equal to

-LT: Less than

-le: Less than or equal to

-eq: Equal

-ne: Not equal to

650) this.width=650; "title=" image "style=" border-right-width:0px;border-bottom-width:0px;border-top-width:0px; " Border= "0" alt= "image" Src= "http://s3.51cto.com/wyfs02/M00/73/75/wKiom1X-qiPQhlbkAADugZA8LKI333.jpg" width= "454" height= "188"/>


String test:

: Greater Than

<: Less than

= =: equals

! = does not equal

-Z $a is empty

-n $a is not empty

=~: Tests whether the left string is matched by the pattern on the right

650) this.width=650; "title=" image "style=" border-right-width:0px;border-bottom-width:0px;border-top-width:0px; " Border= "0" alt= "image" Src= "http://s3.51cto.com/wyfs02/M01/73/73/wKioL1X-rGCShpcUAADYDGT8mGk826.jpg" width= "469" height= "188"/>

File testing: Presence Testing

-E (-a) $file: whether the file exists

-F $file: Exists and is normal file

-D $file: Exists and is a directory

-H $file: exists and is a symbolic link

-L $file: Ibid.

-B $file: exists and is a fast device file

-C $file: exists and is a character device file

-S $file: exists and is a socket file

-P $file: exists and is a pipe file

650) this.width=650; "title=" image "style=" border-right-width:0px;border-bottom-width:0px;border-top-width:0px; " Border= "0" alt= "image" Src= "http://s3.51cto.com/wyfs02/M02/73/73/wKioL1X-rGCDzBqAAABrNiE2WPk855.jpg" width= "481" Height= "/>"

Permission tests:

-R $file: Whether the current user has read access to the file

-W $file: Whether the current user has write access to the file

-X $file: Whether the current user has execute permissions on the file

650) this.width=650; "title=" image "style=" border-right-width:0px;border-bottom-width:0px;border-top-width:0px; " Border= "0" alt= "image" Src= "http://s3.51cto.com/wyfs02/M00/73/73/wKioL1X-rGHR7Mk2AAB6d6ZgttY429.jpg" width= "502" Height= "/>"

-U $file: Whether the current user has suid to the file

-G $file: Whether the current user owns the file: GUID

-K $file: Whether the current user has sticky on the file

650) this.width=650; "title=" image "style=" border-right-width:0px;border-bottom-width:0px;border-top-width:0px; " Border= "0" alt= "image" Src= "http://s3.51cto.com/wyfs02/M02/73/73/wKioL1X-rGGQkGpaAAG-QRWBFwg035.jpg" width= "506" height= "341"/>

650) this.width=650; "title=" image "style=" border-right-width:0px;border-bottom-width:0px;border-top-width:0px; " Border= "0" alt= "image" Src= "http://s3.51cto.com/wyfs02/M01/73/73/wKioL1X-rGGA-vjSAAF7KZyAdEo632.jpg" width= "511" height= "325"/>

-O $file: Whether the current user is the owner of the file

-G $file: Whether the current user is a group of files

650) this.width=650; "title=" image "style=" border-right-width:0px;border-bottom-width:0px;border-top-width:0px; " Border= "0" alt= "image" Src= "http://s3.51cto.com/wyfs02/M00/73/75/wKiom1X-qiWw_yHkAADzSAShweg239.jpg" width= "516" height= "217"/>

$file 1–nt $file 2: Compare the modification timestamp which is close to the current time

$file 1–ot $file 2: Compare the modification timestamp which is far from the current time

$file 1–ef $file 2: Compare two files whether the same inode is executed

650) this.width=650; "title=" image "style=" border-right-width:0px;border-bottom-width:0px;border-top-width:0px; " Border= "0" alt= "image" Src= "http://s3.51cto.com/wyfs02/M01/73/73/wKioL1X-rGLAKIqmAAEU9HTguFc213.jpg" width= "500" height= "246"/>

Combination Test conditions:

with: [[Condition 1–a condition 2]]

OR: [[Condition 1–o condition 2]]

Non: [! conditions]

Each condition refers to an expression

With: Condition 1 && Condition 2

Or: Condition 1 | | Condition 2

Non -:! Conditions

Code reuse

Define the method:

Function name ()

{

Content

}

Name ()

{

Content

}

Return can customize the function state return value, once the return is encountered, the function terminates



An array is a contiguous number of independent memory spaces that are referenced by the array name

BASH4.0 supports 2 kinds of following:

Legacy Arrays: Index-time numbers, starting with 0 declare-a name

Associative arrays: Indexes can be customized and indexed using strings declare-a name


Bash supports sparse-format arrays {0,,,, 6}

Assignment value:

1, Single assignment Name[5]=value

2, all copy name= ("value1" "value2" ...)

3. Specify the index to assign the value name= ([0]= "value1" [3]= "Vlue3")

4. You can use read to assign a value read-a name

The length of the array can be used

${#name [*|@]} to view

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M00/73/77/wKiom1X-uabxZTNvAAEHq8QFYUg628.jpg "title=" 35432. PNG "alt=" wkiom1x-uabxztnvaaehq8qfyug628.jpg "/>


$RANDOM get 0-32767 random numbers.

September 13, Bash summary

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.