Linux上case用法


Linux上case用法示例:

#!/bin/bash
# This is a script for test case
ASK_COUNT=$1            #從參數獲取該變量的值
#
if [ -z "$ASK_COUNT" ]    #判斷ASK_COUNT變量是否為空,為空輸出1,不為空輸出2
then
        echo "1"
else
        echo "2"
fi
echo "ASK_COUNT:$ASK_COUNT"
case $ASK_COUNT in
2)
        echo
        echo "Please answer the question."
        echo
;;
3)
        echo
        echo "One last try... Please answer the question."
        echo
;;
4)
        echo
        echo "Since you refuse to answer the question..."
        echo
        #
        exit
;;
esac  # shell 的風格,用倒序的字母單詞和 正序的單詞配對。比如 if 語句, 結束時用 fi 來配對
#

用法:

[keysystem@localhost 20180202]$ sh case_test.sh 2
2
ASK_COUNT:2

Please answer the question.

[keysystem@localhost 20180202]$ sh case_test.sh 3
2
ASK_COUNT:3

One last try... Please answer the question.

[keysystem@localhost 20180202]$ 

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM