# 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
[ "$yn" == "Y" -o "$yn" == "y" ] && echo "OK, continue" && exit 0
[ "$yn" == "N" -o "$yn" == "n" ] && echo "Oh, interrupt!" && exit 0
echo "I don't know what your choice is" && exit 0
不管输入什么都显示这个,很奇怪,请各位指点,是不是我的VI有问题啊?
[: 10: y: unexpected operator
[: 11: y: unexpected operator
I don't know what your choice is
Y/N程序一直出错,请大家帮忙指点
-
- 帖子: 8
- 注册时间: 2010-04-29 8:58
-
- 帖子: 8
- 注册时间: 2010-04-29 8:58
Re: Y/N程序一直出错,请大家帮忙指点
怎么木有人回阿?是我的问题太白痴了么?
请各位帮忙解答一下,难道是编译器的问题么?
请各位帮忙解答一下,难道是编译器的问题么?
-
- 帖子: 100
- 注册时间: 2008-09-25 16:06
Re: Y/N程序一直出错,请大家帮忙指点
我运行了一下代码没发现什么问题。你打开调试选项查看一下是哪里出了问题。xiangpi1860 写了:# 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
[ "$yn" == "Y" -o "$yn" == "y" ] && echo "OK, continue" && exit 0
[ "$yn" == "N" -o "$yn" == "n" ] && echo "Oh, interrupt!" && exit 0
echo "I don't know what your choice is" && exit 0
不管输入什么都显示这个,很奇怪,请各位指点,是不是我的VI有问题啊?
[: 10: y: unexpected operator
[: 11: y: unexpected operator
I don't know what your choice is
代码: 全选
sh -x 脚本名
Power cloaked in simplicity !
-
- 帖子: 8
- 注册时间: 2010-04-29 8:58
Re: Y/N程序一直出错,请大家帮忙指点
谢谢,终于有人关注了,呵呵
#!/bin/bash
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin
export PATH
read -p "Please input (Y/N): " yn
[ "$yn" == "Y" -o "$yn" == "y" ] && echo "OK,continue" && exit 0
[ "$yn" == "N" -o "$yn" == "n" ] && echo "Oh,interrput!" && exit 0
echo "I don't know what is your choice" && exit 0
我输入的是 y
+ PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:/home/sean/bin
+ export PATH
+ read -p Please input (Y/N): yn
Please input (Y/N): y
+ [ y == Y -o y == y ]
[: 1: y: unexpected operator
+ [ y == N -o y == n ]
[: 1: y: unexpected operator
+ echo I don't know what is your choice
I don't know what is your choice
+ exit 0
输入 e
+ PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:/home/sean/bin
+ export PATH
+ read -p Please input (Y/N): yn
Please input (Y/N): e
+ [ e == Y -o e == y ]
[: 1: e: unexpected operator
+ [ e == N -o e == n ]
[: 1: e: unexpected operator
+ echo I don't know what is your choice
I don't know what is your choice
+ exit 0
是不是我的编辑器出问题了?该怎么做呢?
#!/bin/bash
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin
export PATH
read -p "Please input (Y/N): " yn
[ "$yn" == "Y" -o "$yn" == "y" ] && echo "OK,continue" && exit 0
[ "$yn" == "N" -o "$yn" == "n" ] && echo "Oh,interrput!" && exit 0
echo "I don't know what is your choice" && exit 0
我输入的是 y
+ PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:/home/sean/bin
+ export PATH
+ read -p Please input (Y/N): yn
Please input (Y/N): y
+ [ y == Y -o y == y ]
[: 1: y: unexpected operator
+ [ y == N -o y == n ]
[: 1: y: unexpected operator
+ echo I don't know what is your choice
I don't know what is your choice
+ exit 0
输入 e
+ PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:/home/sean/bin
+ export PATH
+ read -p Please input (Y/N): yn
Please input (Y/N): e
+ [ e == Y -o e == y ]
[: 1: e: unexpected operator
+ [ e == N -o e == n ]
[: 1: e: unexpected operator
+ echo I don't know what is your choice
I don't know what is your choice
+ exit 0
是不是我的编辑器出问题了?该怎么做呢?
-
- 帖子: 100
- 注册时间: 2008-09-25 16:06
Re: Y/N程序一直出错,请大家帮忙指点
仔细看了一下你的程序,发现一个问题。test中用于测试字符串是否相等用的是“=”而不是“==”,所以会提示出错。test用法详见http://www.freebsd.org/cgi/man.cgi?quer ... ormat=html[ e == Y -o e == y ]
[: 1: e: unexpected operator
Power cloaked in simplicity !
-
- 帖子: 8
- 注册时间: 2010-04-29 8:58
Re: Y/N程序一直出错,请大家帮忙指点
hrbeu06ws 写了:仔细看了一下你的程序,发现一个问题。test中用于测试字符串是否相等用的是“=”而不是“==”,所以会提示出错。test用法详见http://www.freebsd.org/cgi/man.cgi?quer ... ormat=html[ e == Y -o e == y ]
[: 1: e: unexpected operator
楼上仁兄正解!太感谢了~