The command line parameters (positional parameters) in Shell programming are similar to the parameter passing of the main function in the C program. These positional parameters are represented by $N, where N is a positive integer, representing the Nth parameter passed in from the command line. N is marked from 0, which is the same way as the array representation in C language. For example, $1 represents the first parameter passed to the script program, and so on. $0 represents the name of the program itself.
The command line parameters are used as shown in the example.
1 #! /bin/sh
2
3 VAR=$1 #将变量$1的值赋值给变量VAR
4 echo "VAR = $VAR"
The output result is as follows. When the script is executed, the first parameter 10 of the command line is passed in, then $1 is assigned the value of 10, and then assigned to the variable VAR, it can be seen that the value of the output VAR is 10.
linux@ubuntu:~/1000phone$ ./test.sh 10 //命令行传输参数值10
VAR = 10 //输出变量VAR的值
linux@ubuntu:~/1000phone$