$0 script execution name
$ N the nth parameter value of the script, n = 1 .. 9
$ * All parameters of the script
$ @ All the parameters of the script (which have similarities and differences with $)
$ # Script parameter count
$ PID for Script Execution
$! PID used to execute the previous background command
$? The Return Value of the previous command.
When you execute the script with more than 9 parameters, you can use the shift command to move the parameters forward to one grid, so that you can use 10th parameters later. In addition, you can use the set command to change $ N and $ *. The method is: Set string is a value of $ *, which is put into $ N after decomposition. If the set command is followed by no parameter, all the preset variables and their values are listed.
File Name: AA. Sh this is a test
Echo filename: $0 filename: AA. Sh
Echo arguments: $ * arguments: this is a test
Echo No. of argS: $ # No. of argS: 4
Echo 2nd Arg: $2 2nd Arg: Is
Shift
Echo No. of argS.: $ # No. of argS: 3
Echo 2nd Arg.: $2 2nd Arg:
Set hello, everyone
Echo arguments: $ * arguments: Hello, everyone
Echo 2nd Arg.: $2 2nd Arg: everyone
For $ * and $ @ running my. Sh p1 "p2 P3" P4 on command line, either $ @ or $ *,
Get P1 P2 P3 P4. But if it is referenced in the program:
"$ @" You can get the three different words (Word) "p1" "p2 P3" "P4 )﹔
"$ *", You can get a single string of words "P1 P2 P3 P4. (The difference is not obvious. Reading NF using awk is equal to 4)
For a big difference, see the following code: AA. Sh
My_fun (){
Echo "$ #"
}
Echo 'number of param in "$ @" = '$ (my_fun "$ @")
Echo 'number of param in "$ *" = '$ (my_fun "$ *")
Then run AA. Sh p1 "p2 P3" P4 and the result is:
Number of param in "$ @" = 3
Number of param in "$ *" = 1