$0: 代表第一個(gè)參數(shù)壁榕,通常是腳本本身的名字
$1: 代表第二個(gè)參數(shù)
...
以此類推
例如:
#!/bin/bash
echo "\$0="$0
echo "\$1="$1
echo "\$2="$2
運(yùn)行結(jié)果:
$ ./a.sh a b
$0=./a.sh
$1=a
$2=b
$@
表示從第一到第n個(gè)參數(shù),例如:
#!/usr/bin/bash
for arg in $@
do
echo $arg
done
運(yùn)行結(jié)果:
$ ./a.sh a b c
a
b
c
還有,當(dāng)入?yún)⒉淮嬖诘臅r(shí)候撵渡,可以有缺省值融柬,例如:
#!/usr/bin/bash
para1=${1:-xxx}
echo $para1
運(yùn)行結(jié)果:
$ ./c.sh abc
abc
$ ./c.sh
xxx
更多內(nèi)容,定義這里姥闭,感興趣的自己看吧:
https://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html
${parameter:-[word]}
Use Default Values. If parameter is unset or null, the expansion of word (or an empty string if word is omitted) shall be substituted; otherwise, the value of parameter shall be substituted.
${parameter:=[word]}
Assign Default Values. If parameter is unset or null, the expansion of word (or an empty string if word is omitted) shall be assigned to parameter. In all cases, the final value of parameter shall be substituted. Only variables, not positional parameters or special parameters, can be assigned in this way.
${parameter:?[word]}
Indicate Error if Null or Unset. If parameter is unset or null, the expansion of word (or a message indicating it is unset if word is omitted) shall be written to standard error and the shell exits with a non-zero exit status. Otherwise, the value of parameter shall be substituted. An interactive shell need not exit.
${parameter:+[word]}
Use Alternative Value. If parameter is unset or null, null shall be substituted; otherwise, the expansion of word (or an empty string if word is omitted) shall be substituted.