1. 程式人生 > >Linux上case用法

Linux上case用法

變量 正序 log span 單詞 local pos 結束 pan

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]$

Linux上case用法