$# is the number of arguments passed to the script. $ is the name of the script itself. $ is the first parameter passed to the shell script, and the second argument that is passed to the shell script is [email protected] is a list of all the parameters passed to the script $* is to display all parameters passed to the script in a single string, unlike positional variables, which can be more than 9 $$ is the current process ID number for the script to run? is to display the exit status of the last command, 0 means no error, others indicate an error
Difference: [Email protected] $*
- Same point: All parameters are referenced
- Different points: only in double quotes. Assuming that three parameters were written when the script was run (stored in $ $ $), "$*" is equivalent to "$ $" (passing a parameter) and "[email protected]" is equivalent to "$" "$" "$" (three parameters passed)
Example One
# #dels. Sh
Echo "number:$#"Echo "scname:$0"Echo "First : $"Echo "second:$2"Echo "Argume:[email protected]"Echo "Show Parm list:$*"Echo "Show Process id:$$"Echo "Show Precomm stat: $?"
Execution results
[@jihite]$ sh del.sh 1 2 3number:3scname:del.shfirst:1second:2argume:1 2 3show parm list:1 2 3show process Id:21057show p Recomm stat:0
Example Two
#!/bin/SHNum=$ #name=$0Echo "Number : $num"Echo "scname: $name"Echo$0Echo$1Echo$2 for((i=0; i< $num; i++)) Do Echo "$i" DoneEcho "Argume:[email protected]" forKeyinch[email protected] Do Echo$key DoneEcho "-----------------" forKeyinch "[email protected]" Do Echo$key DoneEcho "-----------------------------" forKey2inch$* Do Echo$key 2 DoneEcho "-----------------" forKey2inch "$*" Do Echo$key 2 DoneEcho "Show Process id:$$"ChoEcho "Show Precomm stat: $?"
Execution results
[@jihite]$ sh del.sh a b number:2scname:del.shdel.shab01argume:a Bab-----------------AB-----------------------------ab-----------------a bshow process id:23582del.sh:line 37:cho: Command not foundshow Precomm stat:127
Problem:
echo #0 #1 can you use $i to express it?
Linux variable $#,[email protected], meaning of $0,$1,$2,$*,$$,$?