Variable Variablename=value
- Cannot have spaces around equals sign
- Variable content has a space to use "or", but v= "Hello $name" $ to maintain the original function, single quotation marks do not, v= "Hello ' $name '" plain text
- Use escape character \ Convert special characters to normal text ' command ', $ (command), provide command execution information in text
- variable accumulation, name=xiaoyi; Name= $name: ' Welcome to Hz '
- The child process can inherit the environment variable of the parent process but cannot inherit the custom variable of the parent process, export variable name; Change the custom variable to an environment variable
Read the data from the keyboard: Read-p '-t ' to Num v # num time, v variable an array group declaration and use: v[1]= ' hello '; v[2]= ' Xiao ' echo ${v[1]}
Path and command Lookup order
- Execute commands with relative/absolute paths, such as/bin/ls
- This command is found by alias to execute
- Executed by bash built-in commands
- Find the first command to execute by $path the order of this variable
The command to read the shell configuration file is either a point or a dot. , because. BASHRC can only be read at the time of landing, and if it is modified to take effect immediately, we need to call the source command to read the current modified corresponding configuration file Eg:source ~/.BASHRC equals. ~/.bashrc
Pipeline Command scenario: When the data needs to be processed several times before the pipeline comes to the format we want, the first data must be a command that accepts standard input.
Pick Command: Cut,grep
Cut by the Unit of Action cut-d ' break character '-f fields, mainly for split display of row data
Cut-c Character Range
eg
echo $PATH | Cut-d ': '-F 5//select path to: Split fifth
grep analyzes the data we want in a line of information
grep [-ACINV] [--color=auto] ' Find string ' filename
-A binary file looks up data in text mode
-C Statistics match to the number of data
-I ignores case
-N Output line number
-V outputs a row with no matching content grep can be used in conjunction with regular expressions
Sort and Statistics commands sort, WC, uniq
- Sort
sort [-fbmnrtuk] [file or stdin]
-F ignores case
-B ignores the front space
-m sort by month name
-N using pure numeric sorting
-R Reverse Sort
-U The same data item appears only one item
-T delimiter
-K to sort by that interval
eg
cat/etc/passwd | Sort-t ': '-K 1//pair to: Sort the first column of the split
- WC statistic Word, line or character number
WC [-LWM]
-L Number of rows
-W Words
-M character Count
eg
Cat/etc/profile | Wc-lwm
- Uniq duplicate data appears once
Uniq [-ic]
-I ignores case
-C to Count
eg
Last | Cut-d '-f1 | grep ' ^xiaoyi ' | Uniq-c
Character Conversion Instructions TR, col, join, Paste, expand
- TR:TR [-ds] Set1
-D set1 field in delete message
-S replaces duplicate characters
Eg: lowercase for uppercase Last | Tr ' A-Z ' A-Z
Find./-name "*.java" | Xargs wc-l
Find grep speaks the better link: http://www.cnblogs.com/skynet/archive/2010/12/25/1916873.html
Special symbols:
Bird Book Shell Learning Notes (i) Key concepts and commands in the shell