A variable is a variable parameter, a value, a string
- When a certain string is frequently used in the script and the string length is very long, a variable should be used instead, which can save the script capacity; when the variable value changes, only one place needs to be changed, and it is easy to modify
- When using conditional statements, variables are often used if [ $a -gt 1 ]; then ... ; fi
- Substitute a variable for n= when referencing the result of a command
wc -l 1.txt
- When writing scripts that interact with users, variables are also essential read -p "Input a number: " n; echo $n If you don't write this n, you can use $REPLY directly
- Built-in variables $0, $1, $2… $0 represents the script itself, $1 is the first parameter, $2 is the second.... $# represents the number of parameters
- Math operations a=1;b=2; c=$(($a+$b)) or $[$a+$b]