Shell variables, shell scripts basics
Shell variable Categories: environment variables, local variables, local variables, positional variables, special variables
1.shell Local Variables
(1) Assigning values to variables
Name= "Value"
Value
String Name= "string"
Variable reference name= "$name"
Command Reference name= ' command ', name=$
(2) Variable reference
$name,%{name}
"": if referenced, the variable reference is replaced with the value of the variable
': Strong reference, where the variable reference is not replaced with its variable value, keeping the original string
' Command ', $ (command): Commands reference
(3) Delete local variables
unset name
(4) Read-only variable, can not change its value after setting, can not be destroyed, only after the shell process ends its life
ReadOnly Name
Declare-r Name
2.shell Environment variables
(1) Assigning values to variables
Export Name=value
Declare-x Name=value
Local variable promoted to environment variable Expoert name, declaere-x name
(2) Display environment variables
Export
Env
Printenv
3. Deleting variables
unset name
4. Show all variables
Set:set or unset values of the shell options and positional parameters.
5. Position variables
Calling parameters passed to the script from the command line in the script
$, $ ... : corresponding to the command line of the 1th, 2nd ... A parameter
$: Command itself
$*: All parameters passed to the script, all parameters as a whole
[Email protected]: All parameters passed to the script, each parameter is independent
$#: Number of arguments passed in a script
Shift [n]: Kicks out n parameters
6. Logic operation:
&&: With
|| : OR
! : Non-
Short-circuit Operation:
A&&b: If A is false, B is not executed
a| | B: If True, the B is not executed
7. Shell programming Features: Process oriented (sequential execution, loop execution, select execution), interpreting execution
8. The first line of the script indicates the interpreter used to execute the script
#!/bin/bash
#!/usr/bin/python
#!/usr/bin/perl
9. Pstree:display a tree of process: show the tree of processes
Six. Bash script (bash scripts), bash variable