shell會將每個參數(shù)分配給對應(yīng)的變量,變量可以分配數(shù)字,也可以分配字符串。
[注意]每個參數(shù)都是用空格分隔的,所以shell會將空格當(dāng)成兩個值的分隔符。要在參數(shù)值中包含空格,必須要用引號(單引號或雙引號均可)。
*/1 * * * * /root/shell/checkprocess.sh "/usr/sbin/mysqld" "/root/shell/mysqldstart.sh" 。*/1 * * * * /root/shell/checkprocess.sh "/usr/sbin/httpd" "/root/shell/httpdstart.sh" 。shell = /share/cachedev1_data/.qpkg/xunleiyuanchengqnap/xunleiyuanchengqnap.sh為shell = /share/cachedev1_data/.qpkg/script/startxunleiyuanchengqnap.sh。
Hello Rich Blum, glad to meet you.
在第9個變量之后,你必須在變量數(shù)字周圍加上花括號,比如${10}。
如:total=$[ ${10} * ${11} ]
可以用 $0 參數(shù)獲取shell在命令行啟動的腳本名。這在編寫多功能工具時很方便。
"basename" 命令會返回不包含路徑的腳本名。
另外,箭頭鍵,[home],[end],[delete]鍵與bash shell中一樣用法。yubana147:~ home$ -bash: u88:~/source/qsno_cvs home$ printenv path/bin:/sbin:/usr/bin:/sbin:/users/home/bin:/usr/local/bin -bash: -bash:: command not found。shell=/bin/bash shell變量指定了系統(tǒng)要使用哪個shell,這里是bash 。
The script name is: test2.sh
/* 不同功能的腳本 */
#!/bin/bash
# Testing a Multi-function script
#
name=$(basename $0)
#
if [ $name = "addem" ]
then
total=$[ $1 + $2 ]
#
elif [ $name = "multem" ]
then
total=$[ $1 * $2 ]
fi
#
echo
echo The calculated value is $total
[~/shell/4]$: cp test6.sh addem
[~/shell/4]$: chmod u+x addem
[~/shell/4]$: ln -s test6.sh multem
[~/shell/4]$: ./addem 2 5
The calculated value is 7
[~/shell/4]$: ./multem 2 5
The calculated value is 10
在使用參數(shù)前一定要檢查其中是否存在數(shù)據(jù)。如,使用了-n測試來檢查命令行參數(shù)$1中是否有數(shù)據(jù)。
if [ -n "$1" ]
then
echo Hello $1, glad to meet you.
else
echo "Sorry, you did not identify yourself. "
fi
特殊變量$#含有腳本運行時攜帶的命令行參數(shù)的個數(shù)。