在我寫的許多腳本,我使用的是非常具體的if statements
並運行該腳本的用戶提供了2個或多個選項以供選擇,像我的一個腳本,這個例子部分:Shell腳本:如果用戶鍵入意外值,如何重複上次查詢?
read -r -p "How would you like to configure the NRPE daemon? [X]inetd/Standalone [D]aemon " DMN
if [[ "$DMN" = [Xx] ]];
then
DMNMODE="xinetd"
cat <<EOF> $XINETDFILE
service nrpe
{
flags = REUSE
type = UNLISTED
port = $NRPEPORT
socket_type = stream
wait = no
user = $NGUSER
group = $NGGROUP
server = /usr/sbin/nrpe
server_args = -c $NRPECFG --inetd
log_on_failure += USERID
disable = no
only_from = 127.0.0.1 $NAGIOSSRV
}
EOF
$XINETDSVC restart
elif [[ "$DMN" = [Dd] ]];
then
chkconfig nrpe on ; $NRPESVC start
DMNMODE="daemon"
fi
如果用戶鍵入其中一個期望值,那麼一切都可以,腳本按預期工作,但如果其中一個答案中有拼寫錯誤,並且腳本獲取了值,則不知道該腳本退出。 我想確保在出現錯字時用戶不會被踢出腳本......我在想,如果插入錯字,那麼用戶會被問到最後一個問題。 我知道這可以通過使用Case
來實現,但我正在尋找更好的解決方案,您能否幫助我? 在此先感謝
這正是我尋找的更復雜的方式,謝謝! – 2014-10-20 19:04:58