Shell編程-條件判斷-case

語法

在這裏插入圖片描述

注意:*不能加雙引號

#!/bin/bash

read -p "Please input tour name : " -t 30 name

case $name in
        "Finley")
                echo "Hello,Finley ,welcome !!"
                ;;
        "Lin")
                echo "Hello , Mrs.He ,welcome !!"
                ;;
        "*")
                echo "Please dont use the computer,it is not yours"
                ;;
esac

[root@localhost shelltest]# ./case.sh 
Please input tour name : Finley
Hello,Finley ,welcome !!
[root@localhost shelltest]# ./case.sh '
> ;
> dquit
> exit
> ^C
[root@localhost shelltest]# ./case.sh 
Please input tour name : dslfd
Please dont use the computer,it is not your
[root@localhost shelltest]# ./girlf.sh 
 1   |   fengjie    
 2   |   canglaoshi 
 3   |   boduoye    
please input your choice:   1
your choice is fengjie!!
[root@localhost shelltest]# ./girlf.sh 
 1   |   fengjie    
 2   |   canglaoshi 
 3   |   boduoye    
please input your choice:   2
your choice is canglaoshi!!!
[root@localhost shelltest]# ./girlf.sh 
 1   |   fengjie    
 2   |   canglaoshi 
 3   |   boduoye    
please input your choice:   3
your choice is doduoye!!!
[root@localhost shelltest]# 


#!/bin/bash
echo " 1   |   fengjie    "
echo " 2   |   canglaoshi "
echo " 3   |   boduoye    "
read -p "please input your choice:   " -t 30 girl
case "$girl" in
        "1")
                echo "your choice is fengjie!!"
                ;;
        "2")
                echo "your choice is canglaoshi!!!"
                ;;
        "3")
                echo "your choice is doduoye!!!"
                ;;
        *)
                echo "error input !!"
                ;;
esac

在這裏插入圖片描述

特別提醒:

/dev/null如同linux系統的回收站一般
在這裏插入圖片描述
在這裏插入圖片描述


#!/bin/bash

cd /opt/shelltest
touch ls.log
ls *.sh | grep -v deltest.sh > ls.log
ls *.txt>>ls.log
for i in $(cat ls.log)
        do
         rm -rf $i &> /dev/null
        done
rm -rf ls.log

[root@localhost shelltest]# vim deltest.sh 
[root@localhost shelltest]# ./deltest.sh 
[root@localhost shelltest]# ls
deltest.sh

在這裏插入圖片描述

#############################################################################################
# File Name: for.sh
# Author: Finley
# mail: [email protected]
# Create Time: Wed 21 Aug 2019 09:50:09 AM CST
#====================================================================================
#!/bin/bash

declare -i i=0
for (( i=0;i<=100; i++))
        do
                echo "$i "
        done

之前是怎麼寫都出錯,後來發現,在雙小括號裏面,可以用我們在C語言,C++裏面一樣的表達式:
declare -i i=0
for (( i=0;ilt100;i++))doecho&quot;i -lt 100; i++)) do echo &quot;i "
done
一開始是這樣寫的,發現怎麼寫都不對

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章