[Shell Learning] Special variables on the third day

special variables

$n

$n:n为数字,$0代表该脚本名称,$1-$9代表第一到第九个参数,十以上的参数需要用大括号,如${10}

$0:脚本的名称
Insert image description here
$1:执行脚本时命令里对应的参数
Insert image description here

$#

$#:获取所有输入参数的个数
Insert image description here

$*

代表命令行中所有的参数,把所有的参数看成一个整体
Insert image description here

$@

代表命令行中所有的参数,把每个参数区分对待
Insert image description here

$?

$?:最后一次执行的命令的返回状态。0表示上一次成功,否则失败
Insert image description here

Guess you like

Origin blog.csdn.net/weixin_46318413/article/details/129500869