linux bash 常用特殊变量 / arguments , variables / $# $@ $? ...

参数变量

1
2
3
4
5
$#    Number of arguments
$*    All positional arguments (as a single word)
$@    All positional arguments (as separate strings)
$1    First argument
$_    Last argument of the previous command

Note: $@ and $* must be quoted in order to perform as described. Otherwise, they do exactly the same thing (arguments as separate strings).

特殊变量

1
2
3
4
5
6
Special variables
$?	Exit status of last task
$!	PID of last background task
$$	PID of shell
$0	Filename of the shell script
$_	Last argument of the previous command