Self-paced shell scripts

Source: Internet
Author: User

First, learn Zhao Wenyu's summary script:

1. Variables

host=$ (/bin/hostname)
Assigns the result of the command executed in () to the host variable
Host= '/bin/hostname '

Assigns the execution result inside the anti-quotation mark to the host variable

2.echo

echo $? Successful or unsuccessful execution of the last command? is 0

3.if and other statements that require conditional judgment
(1) determine if the file exists and whether it is a file
[-F file]
To determine if a file exists and is a writable file
[-W file]
Determine if a file exists and is an executable file
[-X file]
Determine if a file exists and is a readable file
[-R File]
Determine if a file exists and is a directory file
[-D file]
To determine if a file exists and is an empty file
[-S file]
Determine if a file exists
[-E File]
[] and test function as-A and-O (and, or)

(2) integer value comparison judgment
[-eq]
["$a" = "0"]
((a% 2 = = 0))

Note: ((a = = 50)) The comparison of values, in (()) in the use of No $ are the same


[-N string]//string longer than 0
[-Z string] The length of the//string is 0
String1=string2//String equality
STRING1!=STRING2//strings are not equal
[INT1-GT Int2]//int1>int2 greater than
[Int1-ge Int2]//int1>=int2 greater equal
[Int1-eq Int2]//int1=int2 equal
[Int1-ne Int2]//int1!=int2 not Equal
[Int1-le Int2]//int1<=int2 less equal
[Int1-lt Int2]//int1<int2 less than

(3) character string comparison
["$a" = "$b"]
[-N "$a"] and ["$a"] determine whether the string $ A is empty
[["$a" = = * "Redhat" *]] and [["$a" = * "Redhat" *]] determine-whether a $ A contains a redhat string

(4)if followed by command && and | |
If rpm-q gcc && ID tom| | echo "SSS"//&& if the previous command executes successfully then execute && after the command is executed otherwise | | The following command

4.sed

Sed-ri/^ #ServerName. *:80$/s/^#///etc/selinux/config//Find the line with/etc/seliunx/config beginning with: 80 in #servername file and replace # with blank

5.

Df-th|grep "/$" |awk ' {print $6} ' |sed ' s/%//'//df after intercepting a field and substituting

6.

Self-paced shell scripts

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.