Basic shell syntax in CentOS

Source: Internet
Author: User

Basic shell syntax in CentOS
1. Sorting command

Sort option file name
-F case-insensitive
-N is ordered by numeric values (string type by default)
-R reverse sorting
-T specifies the delimiter (Tab by default)
-Kn [, m] is ordered by the specified range, from n to m (default to the end of the row)
N [, m] can be a single number, for example, 3. A range, for example, 3, 6.
Example:
Sort/etc/passwd
Sort-n-t ":"-k 3, 3/etc/passwd

2. Statistical commands

Wc option file name
-L only number of rows
-W: Number of words only
-M: Only characters

3. if condition judgment statement

If [condition Judgment]; then
Program
Fi
Or
If [condition determination]
Then
Program (condition is true)
[Else
Another program (the condition is not true)]
Fi
Or
Multi-branch if
If [condition judgment 1]
Then
Procedure 1
Elseif [condition Judgment 2]
Then
Procedure 2
.........
.........
Else
(If none of them are available, execute this operation)
Fi

4. case statement

Case $ variable name in
"Value 1 ")
Procedure 1
"Value 2 ")
Procedure 2
;;
.........
.........
*)
If it is not the above value, execute this program
;;
Esac

5. for statement

1)
For variable in value 1 value 2 ......
Do
Program
Done
2)
For (initial value; cyclic control conditions; variable changes ))
Do
Program
Done

6. while and until statements

While [conditional criterion]
Do
Program
Done
Until stands for "until", opposite to "while", that is, as long as the conditional condition is not true, the loop is executed and the loop program is executed. Once the loop condition is true, the loop is terminated. The format is the same as while.

7. Condition judgment

The format is as follows: add the judgment command in brackets [absolute path of the Option file]
Determine by file type

Judge by File Permission

Compare two files

Comparison between two integers

String judgment

Multi-condition judgment

I will not give an example of conditional judgment, but the importance of conditional judgment is self-evident!

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.