2011-12-21 79 views
1

myscript與以下參數失敗,錯誤255(下同)傳遞的參數檢查數的KSH腳本參數

if [ ${#} -ne 7 ] 
echo ${#}   // Actually prints 7 
then 
    echo "ERROR 255: Must provide the following 7 parameters: 
        one two three four five six seven" 
    exit 255 
fi 

所以

  1  2  3    4  5  6  7 
myscript value value /my/path/to/file my_file /tmp/ value value 

檢查數量執行...如果號碼不是7,退出,但確實告訴號碼是什麼.. 7.

世界已經瘋了嗎? :)

回答

3

您確定您的問題中沒有錯別字嗎?

echo ${#}   // Actually prints 7 
if [ ${#} -ne 7 ] 
then 
    echo "ERROR 255: Must provide the following 7 parameters: 
        one two three four five six seven" 
    exit 255 
fi 

有在if [ ... ]then之間的echo ${#}是一個語法錯誤,並讓我KSH炸燬;-)否則,我認爲你的代碼看起來是正確的。

但爲什麼不使用更新的ksh數學評估功能(也許這將解決您的問題)。

echo ${#}   // Actually prints 7 
if ((${#} != 7)) ; then 
    echo "ERROR 255: Must provide the following 7 parameters: 
        one two three four five six seven" 
    exit 255 
fi 

我希望這有助於。