分页: 1 / 1

求教个脚本运行问题

发表于 : 2008-10-11 19:33
michaeldon
我为什么运行如下程序会提示该错误
#!/bin/sh

help()
{
cat << HELP
This is a generic command line parser demo.
USAGE EXAMPLE: cmdparser -l hello -f -- -somefile1 somefile2
HELP
exit 0
}

while [ -n "$1" ]; do
case $1 in
-h) help;shift 1;; # function help is called
-f) opt_f=1;shift 1;; # variable opt_f is set
-l) opt_l=$2;shift 2;; # -l takes an argument -> shift by 2
--) shift;break;; # end of options
-*) echo "error: no such option $1. -h for help";exit 1;;
*) break;;
esac
done

echo "opt_f is $opt_f"
echo "opt_l is $opt_l"
echo "first arg is $1"
echo "2nd arg is $2"
我运行就提示 Syntax error: end of file unexpected (expecting "}")

Re: 求教个脚本运行问题

发表于 : 2008-10-11 19:43
xiooli
我运行没有错误阿。

Re: 求教个脚本运行问题

发表于 : 2008-10-11 19:47
michaeldon
xiooli 写了:我运行没有错误阿。
我也不知道为什么,总是出现那个错误,是不是系统有什么错误呀

Re: 求教个脚本运行问题

发表于 : 2008-10-11 19:49
twwwater
while [ -n "$1" ]; do????????
你是不是想
while [ -n "$1" ]
do
啊?
没有那个分号吧??????/

Re: 求教个脚本运行问题

发表于 : 2008-10-11 20:02
michaeldon
似乎是因为我写第二个HELP没顶格,真邪门

Re: 求教个脚本运行问题

发表于 : 2008-10-11 20:03
solcomo
就是要顶格的

Re: 求教个脚本运行问题

发表于 : 2008-10-12 11:48
twwwater
好像是这样子的......
也没有怎么注意那一个地点.
这种程序好难找错误哦.....