#。 The first sentence in the footsteps, indicating the program used to execute the script
Example: #!/bin/bash
# comments, for help information or for ignoring statements that are temporarily not executed
# This is a comment
$ variable substitution symbol
Example: A=123;echo $a
${} variable regular expression to avoid early truncation of variable names
Example: ${13}
$num Position Parameters
Example: $0,$1,..., ${10}
$? The state of the last command, General 0 is correct, others indicate error
Example: If [$?-ne 0]; Then
echo "Encounter Error"
Fi
$! ID of the background command executed by the last command
Example: pid=$!
$$ the ID of the script process to run
Example: pid=$$
$* passed to the steps of the parameters, add double quotes when the equivalent of "$1$2 ..."
Example: Echo "Theparameters are $*"
$@ is the same as $*, with double quotes equal to "$" ...
Example: a=$@
$# the number of parameters passed to the script without the $ parameter
Example: Echo "theparameter number is $#"
$-saves the current shell's settings information and, if there is I in the result, is an interactive shell
Example: Echo $-
; A separator that writes multiple instructions on the same line
Example: A=123;echo $a
;; Special language case option, which acts like a break in a C-language switch statement
Example: Case${tao} in
A) echo "a";;
b) echo "B";;
Esac
. One represents the current directory and two represents the previous level directory
Example: CD..
, similar to the comma expression in the C language
Example: Let "t1= ((A=5+3,B=7-1,C=15/3))"; Echo $t 1
! Representation of logical operation "non"
Example: If ["$?"! = "0"]; Then
echo "Execute Error"
Exit 1
Fi
: In bash, this is a built-in command, "do nothing", but returns a status value of 0
Example::; Echo$?; :> f.out equivalent to Cat/dev/null > f.out
? Wildcard characters that match any one character, but do not include null
Example: LS f?n
"Treats its contents as strings, and the $ and wildcard characters do not extend or escape
Example: a=1; echo ' $a ' result is $a
"" To use its contents as a string, but $ can be extended, wildcard characters cannot be
Example: b= "string"; echo "$b" result is string
' Inverted quotation mark (on the left of keyboard number 1), where the string is executed as a command
Example: a= ' Date '; echo "$a"
() instruction group that encloses a sequence of instructions, and the shell generates Subshell to execute them
Example: (a=1;echo$a)
(()) bash's built-in functionality for arithmetic operations
Example: a=10;echo$a ((a++)); Echo $a
[] The same as test, used to judge the true and false expression
Example: if [1-eq 2];then
echo ' Kill me '
Fi
[[]] The enhanced version of Bash to [], which allows the use of | | And &&, and you can use regular expressions
Example: Read ver
if [[$ver > 5 && $ $ver < 9]]; Then
echo "That ' s it"
Fi
{} instruction group, similar to (), but executed in the current shell and can also be used for a combination of strings
Example: Mkdir{usera, UserB, UserC}-{home, bin, data}
\<....\> regular expression, matching word first and suffix
Example: Find ' \<the\> ' file
+ addition, regular expression to denote character repeat 1~n times
Example: grep ' 10\+9 ' file
-Subtraction, standard input, last working directory represented in CD command
Example: expr 1-2 + 3; TAR-ZXFV-; cd–
* multiplication, wildcard, representing any character; repetition of one character 0~n times
Example: let "var=2*3"; LS zha*t; grep ' a1[0-9]* '
* * Sub-square operation
Example: Let "var=2**8"
/Division; Directory Separator
Example: Expr 10/2;cd/home/zc
% remainder
Example: expr 10%2
= Assignment; string comparisons, different in [] and [[]] (see = =)
Example: a= "we"; if [$a = = ' wee ']; Then Exit0 fi
= = string comparison, with a single equal sign
Example: a= ' we '
if[[$a = = w*]]; Then
echo "OK"
Fi
!= string comparison, not equal to
Example: if ["$a"!= "$b"]; Then ...
< string comparison, less than; input redirection
Example: Cat>test < Suck.txt
<< read from standard input until separator
Example: 110<< EOF
> Output redirection, file overwrite, no presence, new
Example: Ls>out 2>&1
>> output redirection, the file exists append, does not exist is created
Example: Ls>>out
& Background Execution Work characters
Example: Tar zcvfdata.tar.gz data >/dev/null &
&& logic and short circuit operators
Example: CP 1.txt2.txt && RM 1.txt && Echo ' success '
| Pipe operator
Example: Cat file| grep ' Fan '
|| Logic or, short-circuit operator
Example: RM 1.txt| | echo ' fail '
~ root directory
Example: CD ~
^ The beginning of a matching line in a regular expression
Example: grep ' ^home ' file
\ escape characters, continuation line symbol
Example: echo \ $A = $A \
This is the "the";