解釋:
主要是向腳本中傳遞數據,變量名不能自定義,變量作用是固定的
$n
$0代表命令本身,$1-9代表接受的第1-9個參數,10以上需要用{}括起來,比如${10}代表接收的第10個參數
$*
代表接收所有的參數,將所有參數看作一個整體
$@
代表接收的所有參數,將每個參數區別對待
$#
代表接收的參數個數
例子:
[root@localhost sh]# vi param_test.sh
[root@localhost sh]# cat param_test.sh
#!/bin/bash
echo $0
echo $1
echo $2
echo $#
[root@localhost sh]# sh param_test.sh xx yy
param_test.sh
xx
yy
2
[root@localhost sh]# vi param_test2.sh
[root@localhost sh]# cat param_test2.sh
#!/bin/bash
for x in "$*"
do
echo $x
done
for y in "$@"
do
echo $y
done
[root@localhost sh]# sh param_test2.sh 1 2 3
1 2 3
1
2
3
[root@localhost sh]#