SHELL example integrated _ MySQL

Source: Internet
Author: User
SHELL example 1. if statement

2. interactive selection

3. cyclic judgment

4. numeric operators

5 ,............


If statement format:
If [condition]
Then
Command
Else
Command
Fi


Interactive selection (N can be *)
Echo-e "prompt language, followed by a cursor for input"/c
Read VAR
Case $ VAR in
Y)
Command
;;
N)
Command
;;
Esac


Perform a cyclic check on the condition. if the condition is true, the check will be processed; otherwise, the check will continue.
A = 1
While ["$ a" = "1"]
Do
Fileno = 'ls-l/list/filename * | wc-L'
If ["$ fileno" = "10"]
Then
A = 10
Command
Else
A = 1
Sleep 300
Fi
Done

Grep-v www filename filtering does not contain
Grep www filename filtering inclusion
The uniq-u filter does not have the same row
Uniq-d filter has the same row
Sort sorting
Paste-d ";" filename1 filename2 merge and separate the files.

If ["a" = "10"] # a = 10
["A"-ne "10"] same line
[-S filename] the file size is greater than 0
-S file size greater than 0 returns true
-D is a directory that returns true
-E: the file or directory exists, and the returned result is true.
-If g exists, SGID returns true.
-H: The file is the connection file and returns true
-K files are sticky bits to return true
-Returns true if the r file or directory exists and is readable.
-W: Returns true if a file or directory exists and can be written.
-The u file is SUID and returns true
-X file is executable and returns true

-Eq equals
-Ne is not equal
-Lt is less
-Le is less than or equal
-Gt greater
-Ge is greater than or equal


2*3 + 4 | bc calculates the previous data
Ping-w 2 www.163.com test 2 twice
Last Command result judgment
$? = 0 true
$? = 1 is false


Add parameters to SHELL
XXXX = 'echo | wc-C'
Cat $ HOME/list/file.txt 1>/dev/null 2>/dev/null
OK = $?
If ["" = ""] | ["$ XXXX"-lt "4"] | ["$ OK"-ne "0"]
Then
Echo "inputs are not input. the input number is not equal to 3. File.txt does not exist. please enter them again"
Exit
Fi


One loop check
Line = 1
For I in 'cat BB'
Do
Qq = 'echo "scale = 2; $ I * 100" | bc | awk-F. '{print }''
If ["$ qq"-ge "75"]
Then
Sed-n "$ line" p temp.1> bad.1
Fi
Line = 'expr $ line + 1' ### add 1 at a time
Done

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.