$# is the number of arguments passed to the script 0 is the name of the script itself $ 1 is the first parameter passed to the shell script $ 2 is the second parameter passed to the shell script [email protected] is a list of all parameterspassed to the script $ * is a single string to display all the parameters passed to the script, different from the location variable, the parameters 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:@*
- Same point: All parameters are referenced
- Different points: only in double quotes. Suppose that three parameters were written when the script was run (stored in123) then " * "Equivalent to"123"(Mass transferHandedThe one Ginseng number ) ;" @ "equivalent to" 1""2 "" $ $ "(three parameters passed)
Example one:
1# #dels.SH2 Echo "number:$#"3 Echo "scname:$0"4 Echo "First : $"5 Echo "second:$2"6 Echo "Argume:[email protected]"7 Echo "Show Parm list:$*"8 Echo "Show Process id:$$"9 Echo "Show Precomm stat: $?"
The result of the execution is:
[@jihite]$SHDel.SH 1 2 3Number :3Scname:del.SHFirst :1Second:2Argume:1 2 3show Parm list:1 2 3Show ProcessID:21057Show PrecommStat:0
Example two:
1#!/bin/SH2num=$#3name=$04 Echo "Number : $num"5 Echo "scname: $name"6 Echo$07 Echo$18 Echo$29 Ten for((i=0; i< $num; i++)) One Do A Echo "$i" - Done - the Echo "Argume:[email protected]" - forKeyinch[email protected] - Do - Echo$key + Done - Echo "-----------------" + forKeyinch "[email protected]" A Do at Echo$key - Done - Echo "-----------------------------" - forKey2inch$* - Do - Echo$key 2 in Done - Echo "-----------------" to forKey2inch "$*" + Do - Echo$key 2 the Done * $ Echo "Show Process id:$$"Panax Notoginseng Cho - Echo "Show Precomm stat: $?"
Execution Result:
1[@jihite]$SHDel.SHa B2Number23Scname:del.SH4Del.SH5 a6 b7 08 19 argume:a bTen a One b A----------------- - a - b the----------------------------- - a - b ------------------ + a B -Show processID:23582 +Del.SH: LinePanax Notoginseng: Cho:command not found AShow PrecommStat:127
Problem:
echo #0 #1 can you use $i to express it?
Stamp me with the original address
What is the meaning of variable #,@,0,1,2,*,$$,$ in Linux?