Variable
1. Custom Variables
① variable = variable value
X=5
Name= "Jie Chao" (the symbol in double quotes has meaning, the symbol in single quotation marks has no meaning)
② Call $name
③ Variable Overlay
x=123,x= "$x" 456
④ Delete variable unset variable name (without $ symbol)
⑤ View all variable set
2. Environment variables
① Setting Environment variables
Export variable = variable name
② Viewing environment Variables env
③path variable, the path of the system search command
3. Positional parameter Variables
① $n N=0..9:n is a number, and $ A represents the command itself, $1-$9 represents the first to nineth arguments, and more than 10 arguments are enclosed in curly braces, such as ${10}, to pass the input parameters to the script. Cases:
#!/bin/bash
Num1=$1
Num2=$2
sum=$ (($num 1+ $num 2))
Echo $sum
②$* returns the input parameters to the script and considers all parameters as a whole
③[email protected] Returns the input to the script parameter, treats each parameter differently
④$# returns the number of input-to-script parameters
#!/bin/bash
echo "\$* can shu Shi: $*"
echo "\[email protected] can shu Hai shi: [email protected]"
echo "\$# can shu ge shu shi: $#"
4. Pre-defined variables
①$? Determine if the previous command was executed correctly, the return value of 0 indicates correct
②$$ PID of the current process
③$! The last process number running in the background
5. Accept keyboard Input
read [options] [variable name]
-P: Prompt information
-T: Number of seconds to wait for input, over wait time program terminates
-N: Directly subject to the specified number of characters
-S: input is not displayed (password input)
Eg:read-p "Please input your name:"-T-Name
Read-p "Please input secret:"-t 30-s Age
Simple solution of Linux variables