关闭

Shell scipt两种判断方式

321人阅读 评论(0) 收藏 举报
分类:

1、

#!/bin/bash
#Program:
#    This program shows the user's choice 
#History:
#    2013/08/26  ydonghao
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin
export PATH

read -p "Please input (Y/N): " a
echo $a
[ $a=Y -o $a=y ] &&  echo "OK, continue" && exit 0
[ $a=N -o $a=n ] &&  echo "Oh, interrupt" && exit 0
echo "I don't know what your choice is" && exit 0

2、

#!/bin/bash
#Program:
#    This program shows the user's choice 
#History:
#    2013/08/26  ydonghao
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin
export PATH

read -p "Please input (Y/N): " yn

if [ "$yn" = "Y" ] || [ "$yn" = "y" ]; then
    echo "OK; continue "
    exit 0;
fi
if [ "$yn" = "N" ] || [ "$yn" = "n" ]; then
    echo "oh, interrupt "
    exit 0;
fi
echo "I don't know what your choice is" && exit 0


0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:64936次
    • 积分:1616
    • 等级:
    • 排名:千里之外
    • 原创:93篇
    • 转载:54篇
    • 译文:1篇
    • 评论:3条
    最新评论