Shell Basics: Shell variables, environment variable profiles, shell special characters _cut, sort, WC, uniq

Source: Internet
Author: User

Shell Variables

1. Order env to list all system variables (all uppercase letters) of system presets

2. The command set can see the variables that are preset by the system, or you can see the user-defined variables.


3. Custom variables:

Rules for variable names: letters, numbers, and underscores, the first cannot be numbers

4. You need to enclose the variable value in single quotation marks when it has a special symbol

(using double quotation marks will make an error)

When you use double quotes to amplify a variable, it interprets the value of the variable


5. Global Variables

How to change a custom variable to a global variable?

(1) export variable name = variable Value

Export Cansheng=handsome

The variables defined in this way are global environment variables

( the global variable here is the downward relationship, which is to generate a global variable at the current terminal (bash), and when we open a child shell (executing command bash), it is possible to output this global variable. However, a global variable is generated under a child shell and is not valid if the global variable is opened at the parent level. Relationship irreversible )


environment variable configuration file (not used in work)


1./etc/profile and/ETC/BASHRC try not to modify

Modify the profile and BASHRC in the user's home directory.

(/etc is under the system)



2.ps1 defined under/ETC/BASHRC

PS1 is related to the section in front of our command line.


Shell Special Character _cut command

# comment Characters:

\ de-Semantic characters:



Command cut: Split

-D: followed by a split character, separated by single quotation marks "

-F: The next section is followed by the number of blocks

-C: followed by the first character (use-C do not use-D)


Sort command: Sort

-N: Sort by number

-r: Indicates reverse ordering

-T: followed by delimiters, separators do not need to be enclosed in single quotation marks.

-U: Remove Duplicates

-KN1,N2: Indicates that the N1 interval is sorted to the N2 interval


WC command: Statistics

-L: Count rows

-M: Statistics of characters

-W: Number of statistical words (separated by spaces)


Uniq command: To repeat

-C: Count of duplicate rows


The Uniq command is used in conjunction with the sort command,

Sort first, then go back.


Tee command: Similar to > Output redirection (you can see the input result (process) printing process. )

Tee-a similar Append


TR Command: Replacement character


Split command: Cutting documents

-B: Indicates size (default is byte)

-L: Indicates the number of rows

The cut ends with X.

split-b 100k a.txt ABC (specifies that the file starts with ABC after the cut )


Shell special symbol (bottom)

&> redirect Errors and correct redirects to the same file

|| To express or to mean

(The following command is executed when the previous command is unsuccessful, the current face executes successfully, and subsequent commands are not executed)

&& the meaning of (when the previous execution succeeds, the latter is executed; the front is unsuccessful and not executed later)


Shell Basics: Shell variables, environment variable profiles, shell special characters _cut, sort, WC, uniq

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.