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: 2206952220@qq.com
# 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 &quot; i -lt 100; i++)) do echo &quot; ilt100;i++))doecho"i "
done
一开始是这样写的,发现怎么写都不对

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值