During script execution, if there are some commands or paths that are long and need to be used repeatedly. Variables are used instead, which makes it easy to change and maintain.
Read-t3-p "Please input a number:" N
Echo $n
Read is commonly used to implement human-computer interaction , and assigns the input value to the variable n -t3 specified time-out, more than 3 seconds, and returns to the system prompt.
Built-in variables in the shell: $ $1-$9 $ #等
Vim test.sh
Example: Echo "\$0=$0"
echo "\$1=$1"
echo "\$2=$2"
echo "\$#=$#"
To show $1=? Format, the default is $1-$9 null. where $ A defaults to the file name, $ #为所有参数的个数
Execute bash test.sh AA 2c will be assigned to $ $ and 2c respectively
Variables for mathematical operations:
A=1;b=2;c= $a + $b; Echo $c result is 1+2, no mathematical operation
a=1;b=2;c=$[$a + $b]; Echo $c result is 3, which is a fixed notation for mathematical operations []
1.4-shell Custom Variables