Shell scripting improves

Source: Internet
Author: User
Tags case statement

Shell scripting improves

Date//view dates and times

-S change Time date-s "2015-08-20 14:27:12"

View time Date + "%y-%m-%d%h:%m:%s"

-D Change Single time Date-d "-2 Days" +%f

+%w Show weeks

+%w show how many weeks this year

ntpdate //Calibration time ntpdate ntp.fudan.edu.cn use Fudan University server proofing time. Need to install NTP package


cal //view calendar of the month

-y view calendar throughout the year

Built-in variables

The first parameter

$ A second parameter

$ A script itself name

$# Number of parameters


Common symbols

>-gt greater than

=-eq equals

<-lt less than

! =-ne Not equal to

>=-ge greater than or equal to

<=-le less than or equal to


-F is set when it is a file

-D is established when it is a directory

-R set up when the file is readable

-W When the file can be written to be established

-X when the file executable is established

-N When the variable is not empty, set up

-Z When the variable is empty

If statement

First Kind

If condition judgment

Then

Results

Fi


The second Kind

If condition judgment

Then

Results

Else

Results

Fi


Third Kind

If condition judgment

Then

Results

Elif

Then

Results

Else

Results

Fi



Case statement

Case parameter in

Condition judgment)

Results

;;

Condition judgment)

Results

;;

*)

Results

;;

Esac



For statement

SEQ//command to generate sequence

SEQ 1 10//Display sequence

SEQ 1 2 10//Set step

SEQ 10-2 1//Reverse

seq-w 01 10//Plus-W parameter sets the number of sequence bits by the maximum number width


The for reference variable in condition is judged

Do

Output results

Done


While statement

In an uninterrupted loop statement, ":" Is always true

While condition judgment

Do

Results

Done


Break continue exit statement

Break//End entire loop

Continue//end of this cycle

Exit//End the entire shell directly


Function can be thought of as a fragment of a shell, or a small unit

Function name () {

Statement

}


Function name (call)


Local//Use local variables, only in child functions

function can be omitted



Array

A= (1 2 3 4)//define Array

echo ${a[@]}//display array

echo ${a[*]}//Replace @ with * can also output array

echo ${a[0]}//Output first digit

a[2]=7//Change a number

echo ${#a [*]}//Plus # statistics total

Random number four-bit or five-bit

echo ${a[@]:0:4}//print four random numbers


Shell scripting improves

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.