代码: 全选
#!/bin/bash
# Program:
# This program shows the user's choice
# History:
# 2005/08/25 VBird First release
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
Please input (Y/N): y
sh06-2.sh: 11: [: y: unexpected operator
sh06-2.sh: 11: [: y: unexpected operator
sh06-2.sh: 15: [: y: unexpected operator
sh06-2.sh: 15: [: y: unexpected operator
I don't know what your choice is
但是在centos下执行结果如下:
Please input (Y/N): y
OK, continue
不支持[]表达式么?怎么弄才支持?