我有這樣的shell腳本。shell腳本錯誤
line="[email protected]" # get the complete first line which is the complete script path
name_of_file = ${line%.*}
file_extension = ${line##*.}
if [ $file_extension == "php"]
then
ps aux | grep -v grep | grep -q "$line" || (nohup php -f "$line" > /var/log/iphorex/$name_of_file.log &)
fi
if [ $file_extension == "java"]
then
ps aux | grep -v grep | grep -q "$line" || (nohup java -f "$name_of_file" > /var/log/iphorex/$name_of_file.log &)
fi
這裏線變量具有像/var/www/dir/myphp.php
或/var/www/dir/myjava.java
值。
shell腳本的目的是檢查這些進程是否已經在運行,如果沒有,我嘗試運行它們。我得到以下錯誤。
name_of_file: command not found
file_extension: command not found
[: missing `]'
[: missing `]'
任何想法?
您需要的緊密報價'間空隙的支架問題「'和括號''''如下所示...''php」]' – 2011-03-11 13:57:34
什麼shell?腳本是否以'#!'開頭? – nmichaels 2011-03-11 13:58:12
然後我得到'name_of_file:找不到命令 FILE_EXTENSION:找不到命令 [:==:一元運算符預期 [:==:一元運算符expected' – ayush 2011-03-11 13:59:05