In the shell, $* and [email protected] respectively represent the following meanings:
$ A: The name of the script itself
$#: Number of positional parameters
$*: All positional parameters will be treated as a string
[Email protected]: Each positional parameter is considered a separate string
$$: PID of the current process
$! : The PID of the last daemon run by the shell
$? : Returns whether the last command was successful, 0 indicates successful execution, and not 0 indicates execution failed
$1~ $n: each parameter value added to the shell. $ $ is the 1th parameter, and the $ = is the 2nd parameter ....
Example:
#!/bin/bashecho "The name of this shell script is: $" echo "first param is:" echo "Second param is: $" echo "third param is: $ "echo" The total number of param are: $# "for I In" $* ";d o echo $idonefor n in" [email protected] ";d o echo $n Doneecho "The PID of current process: $$" echo $!
Test results:
[[email protected] ~]# bash var_1.sh a b cthe name of this shell script is:var_1.shFirst param is:asecond param is:bthi RD param is:cthe Total number of param is:3a b cabcthe PID of current process:20022[[email protected] ~]# echo $?0
The difference between $* and [email protected]:
As can be seen from the test results, $* is the use of all positional parameters as a string input, while [email protected] is to use each positional parameter as a separate string output.
This article is from the "Running Snail" blog, please make sure to keep this source http://441274636.blog.51cto.com/5054639/1890303
Special variables in the shell ($, $#, $*,[email protected], $$, $!, $, $1~ $n)