Terminal, the interface program attached to the terminal:
GUI: KDE, GNome, Xfce
CLI: / etc / shells
bash features :
command line expansion: ~, {}
command alias: alisa, unalisa
command history: history
file name wildcard: glob
Shortcut key: Ctrl + a, e, u, k, l
command completion: $ PATH
path completion:
bash feature command hash
cache previous search results: key-value key: search key value: value
hash command
hash: column a
hash -d command: command to delete the cache
hash -r: empty
bash of features: variable
program: instruction data +
instruction: providing a program file
data: the IO devices, files, pipes, variable
program: algorithms + data structures
variable Name + pointed to the memory space
variable assignment: name = value
Variable type: storage format, data range, participating operation
programming language:
strong type variable
weak type variable:
- bash treats all variables as characters
- Variables in bash do not need to be declared in advance.
Variable replacement: replace the position where the variable name appears with the data
variable reference in the memory space pointed to : $ (var_name), $ var_name Generally, parentheses can omit the
variable name: the variable name can only contain numbers, Letters and underscores, and can not start with numbers, can not use the reserved characters of the program, such as: if, else, then, while
Bash variable type:
Local variables : The scope is only the current shell process
- Variable assignment: name = value
- Variable reference: $ {name}, $ name can omit the curly braces in most cases
- View variable set
- Undo variable: unset name is not a variable reference here, so don't use $
Environment variables:
Variable assignment:
- export name=value
- name=value
export name - declare -x name= value
- name=value
declare -x name
Variable assignment:
local variable: scope is only a certain code snippet (function context)
positional parameter variable: the parameter passed when the shell process executing the script
special variable: a variable with special functions built into the shell
- $?
- 1 0: Success
- 21-255: Failure
Note: bash built a number of environmental variables (usually all uppercase) used to define the bash of the working environment
PATH, HISTFILE, HISTSIZE, HISTFILESIZE, HISTCONTROL, SHELL, HOME, UID, PWD, OLDPWD
viewing environment variable : Export, declare -x, printenv, env
undo environment variable: unset name
read-only variable:- declare -r name
- The readonly name
read-only variable cannot be reassigned and does not support undo: the storage time is the life cycle of the current shell process, which terminates as the shell process terminates
Bash features many command execution:
~] # COMMAND1; COMMAND2; COMMAND3; ............
Logical operation:
operand: true (true, yes, on, 1) false (false, no, off, 0)
- 与:
1&&1=1
1&&0=0
0&&1=0
0&&0=0 -
Or:
1 || 1 = 1
1 || 0 = 1
0 || 1 = 1
0 || 0 = 0 - Not
:! 1 = 0
! 0 = 1
Short circuit rule:
~] # COMMAND1 && COMMAND2
COMMAND1 is "false", then COMMAND2 will not run
If COMMAND1 is "true", then COMMAND2 must run