1 PATH environment variable
2 Use of redirects
0 Callout Enter default keyboard input, you can use other content to redirect the correct output on the 1 standard output screen
2 error output &> redirect
all output
redirection symbols are:
> >>
2>&1 indicates that the error output is redirected to the standard output
Example 1
find/etc/-name "*.conf" >>/tmp/file1 2> &1
Example 2
uses the cat command to demonstrate redirection features
cat >/tmp/file.txt << endf
Hello World
endf
3 Note Special characters in the script
4 "and $ () Execute command
The standard way to call 5 variables is ${varname}, where curly braces are usually omitted
6 seq Command generation sequence
7 $ (()) and $[] commands are used to compute
8 for Loop
For VAR in List;do
commond
Done
9 script mode using the BASH-X option
10-bit variables
$ $ indicates that the script name $# the number of parameters passed $* all parameters, is all taken out $@ also table all parameters, but one of the fetch
11 The exit status of the command $? 0 indicates correct, non 0 indicates error exit number can specify exit status in script
12 There are many operators in the script [EXPRESSION] or the test command to make conditional judgments: 1 integer Comparisons-eq-ne-gt-ge-lt-le
2) string comparison = = etc
!= Range
3) string Evaluation-Z string is null-n string is not null
4 Comparison of file-B-block file-C character file-D directory-e file existence-F general file-L Symbolic link file-r read-only file-W has write permission files--------------------file with Execute permissions--File size greater The point number is the same-nt FILE1 modification date is earlier than FILE1 FILE2 late-ot FILE2
5 logical Operation && and | | Or
13 piece Structure 1) if statement
If Condition1;then
STATeMENT
elif condition2;then
STATeMENT
else
STATeMENT
fi
2) Case statement
Case VALUE in
PATTERN1)
STATEMENT ...
STATEMENT;
;
PATTERN2)
STATEMENT ...
STATEMENT;
;
pattern3| PATTERN4)
STATEMENT ...
STATEMENT;
;
[A-
z] STATEMENT;
;
[0-9])
STATEMENT;
;
*)
STATEMENT
;;
Esac
The While Loop statement
While CONDITION
doing
STATEMENT
done
In addition, there is a common use of read-by-line reads:
While read CONDITION
did
STATEMENT done
< InputStream
15 about environment Variables shell and script use variables to store data, and some variables can be passed along with their content to child processes, which are called environment variables. Marks a variable as an environment variable through the Export command.
One use scenario for environment variables is to initialize the shell environment after the user logs in. Commonly executed shell environment initialization scripts are (in the order of execution from top down):/etc/profile #系统环境变量 |__/etc/profile.d ~/.bash_profile #用户环境变量 |__ ~/.BASHRC |__/ETC/BASHRC
Logon scripts are generally divided into two types: configuration files and RC files. Configuration files are used to set up and export environment variables, and to run commands that should run only after landing, and RC files (such as/ETC/BASHRC) are used to run commands, set aliases, define functions, and other settings that cannot be exported to a child shell. Typically, the configuration file executes only in the login shell, and the RC file is executed each time the shell is created.
16 Alias Alias
#生成别名
alias newcmd= ' CMDS '
#取消别名
unalias newcmd
17 using function functions is a way of isolating code snippets that can be used to repeatedly invoke code without having to rewrite the same functionality
FuncName () {
statements
}