Shell commands are generally divided into built-in (self-contained) and exotic (except those that come with the Yum installation later)
How to produce a built-in command: $ man Bash 1 (why add a 1 here because of the manual format)
The composition of the Man Handbook
MANUAL SECTIONS
The standard sections of the manual include:
1 User Commands # #用户命令
2 System Calls # # Systems Call
3 C Library Functions #C函数库
4 Devices and Special Files #设备和特殊文件
5 file Formats and Conventions # files format and conventions
6 games et. Al. #游戏
7 Miscellanea Miscellaneous
8 System Administration Tools and Deamons #系统管理工具
Distributions Customize the manual sections to their specifics, which often include additional sections.
General distinction built-in tips: Help command in general if it is a built-in command will generally give a simplified syntax format, enough to apply.
$ help CD
Common Command parsing:
Echo (Output information on screen) option-N (File not wrapped)-E (special character that can recognize \ Begins)
$ echo-n Hello
Hello[[email protected] ~]$ (displayed with the command environment variable because no newline)
Compare the difference between-e and no;
$ echo "A\NB\NC"
A\nb\nc
$ ECHO-E "A\NB\NC"
A
B
C
Common special characters: \ n line break \ r enter \ t tab (equivalent to pressing TAB key)
Application of Shell variables: (The experiment here is to first define a variable var=abcabc123abcabc)
1. Return the contents of the variable ($var ${var})
$ echo $var
Abcabc123abcabc
$ echo ${var}
Abcabc123abcabc
2. Return length (${#var}) is to add # before entering Var
1. $ echo ${#var}
15
2. View length can also be used with wc-l (here is the uppercase L, do not use C)
$ echo $var |wc-l
15
$ wc-c (there's going to be a bit more here.) \ n)
$ echo $var |wc-c
16
Below we look at the $ echo through the OD command what do $var do?
The OD command is used to output a file's octal, hexadecimal, or other encoded bytes, which are typically used to display or view characters in a file that cannot be displayed directly in the terminal.
$ Echo ' echo $var |od-c '
0000000 a b c a B C 1 2 3 a b c a B c \ n 0000020
There's one more here. So the WC has one more character when it comes to counting characters.
Refresher: WC command Prompt
-C,--bytes
Print the byte counts
-L,--max-line-length
Print the length of the longest line,
3. The length method that comes with expr
$ Echo ' Expr length $var '
15
3. Use variable ${} to delete
matching rules;
# indicates the shortest start match
# # Indicates the longest start match (more greedy)
% = Shortest match from end
Percent is the longest match from the end (more greedy)
For example
$ echo ${var}
Abcabc123abcabc
$ echo ${var#a*c}
Abc123abcabc
$ echo ${var# #a *c}
$ echo ${var%a*c}
Abcabc123abc
$ echo ${var%%a*c}
[S[email protected] ~]$
Here 3 and 5 are differentiated to be noted. # #从前面匹配的而 percent is matched from face to face.
4. Replace with variable ${}
$ var=ababab
$ echo $var
Ababab
$ echo ${var/a/a}
Ababab
$ echo ${var//a/a}
Ababab
Note Here is the difference:/is to replace the first character. Replace all characters
Also: There is a confusing place to read the system scripts:
For example, there are a few similar words in/ETC/INIT.D/HTTPD
HTTPD=${HTTPD-/USR/SBIN/HTTPD}
View Manuals:
${parameter:-word}
Use Default Values. If parameter is unset or NULL, the expansion of word is substituted. Otherwise, the
Value of parameter is substituted.
This usage means that if the variable is not assigned or is empty, the word string is returned and the value of the variable is substituted.
Prevents the absence of a variable from causing an exception and returns the value used if the variable is undefined (word)
This article is from the "Shong Linux Tour" blog, make sure to keep this source http://12042068.blog.51cto.com/12032068/1893840
Shell Experience Two