分页: 1 / 1

求教!

发表于 : 2013-08-15 17:06
轩辕傲竹
#!/bin/bash
#program:
# This program shows the user's choice
#History:
# 2013/08/15 lvyangjian firstrelease
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 what your choice is " && exit 0
~
结果显示
sh06.sh: 10: [: Y: unexpected operator
sh06.sh: 11: [: Y: unexpected operator
I don't what your choice is

请问是哪里错了

Re: 求教!

发表于 : 2013-08-15 17:13
YeLee
脚本没错,是shell错了。

Re: 求教!

发表于 : 2013-08-15 21:53
轩辕傲竹
shell错了?错在哪里,是编码问题还是什么?

Re: 求教!

发表于 : 2013-08-16 2:22
lxf1992521
Shell 执行错误,看下面的结果:

代码: 全选

$ sh ll.sh
please input (Y/N): 
[: 10: unexpected operator
[: 11: unexpected operator
I don't what your choice is
正确方法是:
1.

代码: 全选

bash shell脚本.sh
2.

代码: 全选

chomd a+x shell脚本.sh
./shell脚本.sh