Shell scipt两种判断方式

来源:互联网 发布:淘宝店直通车怎么开 编辑:程序博客网 时间:2024/06/07 11:44

1、

#!/bin/bash#Program:#    This program shows the user's choice #History:#    2013/08/26  ydonghaoPATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/binexport PATHread -p "Please input (Y/N): " aecho $a[ $a=Y -o $a=y ] &&  echo "OK, continue" && exit 0[ $a=N -o $a=n ] &&  echo "Oh, interrupt" && exit 0echo "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  ydonghaoPATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/binexport PATHread -p "Please input (Y/N): " ynif [ "$yn" = "Y" ] || [ "$yn" = "y" ]; then    echo "OK; continue "    exit 0;fiif [ "$yn" = "N" ] || [ "$yn" = "n" ]; then    echo "oh, interrupt "    exit 0;fiecho "I don't know what your choice is" && exit 0