2014-10-31 121 views
1

我有一個運行在BusyBox linux安裝上的bash腳本。雙輸入運行腳本

當我運行我的腳本,在提示我要進入yes和下面的輸出:

Remove existing upgrades stored on this device? 

Please answer yes or no. 

    Remove existing upgrades stored on this device? Please answer yes or no. 

    Remove existing upgrades stored on this device? 

yes了它mvoes進入第二個條目,並運行在case下是命令循環。任何想法,爲什麼我必須輸入兩次?

這裏是我使用的代碼示例:使用下面我的解決方案的IF Statement

while true; do 
    read -p " Remove existing upgrades stored on this device? " yn 
    case $yn in 
     [Yy]*) 
     echo " Moving into folder." 
     echo " Removing existing upgrade files." 
     echo " Moving back to original folder." 
     echo " Complete."; 
    break;; 
     [Nn]*) 
     echo " Enough space is available." 
     echo " This script can be run again if required."; 
    break;; 
     *) 
     echo "Please answer yes or no." 
     echo "";; 
    esac 
done 
+0

如果我必須這樣做的話,我將輸入轉換成小寫或大寫,然後把它放到case語句 – Ashish 2014-10-31 09:09:58

+0

«任何想法,爲什麼我必須輸入兩次?»我試圖從'提示腳本bash',它運行良好,無需輸入兩次我的答案。接下來,我開始了一個'busybox'會話,就像'busybox sh'中一樣,並且從新的提示中我再次執行了腳本,再次沒有問題。在這兩種情況下,我嘗試了所有的組合,不是,也許是我能想到的。道德上,在我看來,你對'busybox'的具體問題有問題,你應該考慮在你的問題中增加更多細節。 – gboffi 2014-10-31 09:18:22

+0

@gboffi謝謝,我還有一個Fedora機器,腳本按預期運行,但在我的BusyBox機器上它要求雙輸入。我提供了儘可能多的信息,並希望可能有人遇到類似的情況,並可能幫助我! – 2014-10-31 09:20:27

回答

0

我已經重建了腳本,這一次。

如果任何人有關於如何保持while循環的建議,我仍然喜歡聽到它。

read -p " Remove existing upgrades stored on this device? (y/n) " RESP 
if [ "$RESP" = "y" ]; then 
    echo " Moving into folder." 
    echo " Removing existing upgrade files." 
    echo " Moving back to original folder." 
    echo " Complete."; 
else 
    echo " Enough space is available." 
    echo " This script can be run again if required."; 
fi 
相關問題