Linux variable $[#,@,0,1,2,*,$,?] Meaning
$# 是传给脚本的参数个数
$
0
是脚本本身的名字
$
1
是传递给该shell脚本的第一个参数
$
2
是传递给该shell脚本的第二个参数
[email protected] 是传给脚本的所有参数的列表
$* 是以一个单字符串显示所有向脚本传递的参数,与位置变量不同,参数可超过
9
个
$$ 是脚本运行的当前进程ID号
$? 是显示最后命令的退出状态,
0
表示没有错误,其他表示有错误
Difference: [email protected], $*
Same point: All parameters are referenced
Differences: $* and [email protected] All represent all parameters passed to a function or script, and are not enclosed by double quotation marks (""), with "$" "$" ... All parameters are output in the form "$n". But when they are enclosed in double quotation marks (""), "$*" takes all the parameters as a whole and outputs all parameters in the form of "$ $ ... $n"; "[email protected]" separates the various parameters to "$" "$" ... All parameters are output in the form "$n".
$* and [email protected] detailed differences please see here
#!/bin/BashEcho "-----------------" forKeyinch "[email protected]" Do Echo '[email protected]'$key DoneEcho "-----------------------------" forKey2inch$* Do Echo '$*'$key 2 Done1, quoted execution and results: [[email protected]~]# Bashfile.SHLinux "python C" -----------------[email protected] linux[email protected] python c-----------------------------$*linux$*python$*C2, without quotes execution and results: [[email protected]~]# Bashfile.SHLinux python c-----------------[email protected] linux[email protected] python[email protected] C-----------------------------$*linux$*python$* C
Execute script parameter acquisition in Linux