Shell编程-条件判断-case

语法

Shell编程-条件判断-case_第1张图片

注意:*不能加双引号

#!/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

Shell编程-条件判断-case_第2张图片

特别提醒:

/dev/null如同linux系统的回收站一般
Shell编程-条件判断-case_第3张图片
Shell编程-条件判断-case_第4张图片


#!/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

Shell编程-条件判断-case_第5张图片

#############################################################################################
# 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; i − l t 100 ; i + + ) ) d o e c h o " i -lt 100; i++)) do echo " ilt100;i++))doecho"i "
done
一开始是这样写的,发现怎么写都不对

你可能感兴趣的:(shell)