求教个脚本运行问题

sh/bash/dash/ksh/zsh等Shell脚本
回复
michaeldon
帖子: 7
注册时间: 2008-10-11 19:18

求教个脚本运行问题

#1

帖子 michaeldon » 2008-10-11 19:33

我为什么运行如下程序会提示该错误
#!/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 "}")
头像
xiooli
帖子: 6956
注册时间: 2007-11-19 21:51
来自: 成都
联系:

Re: 求教个脚本运行问题

#2

帖子 xiooli » 2008-10-11 19:43

我运行没有错误阿。
michaeldon
帖子: 7
注册时间: 2008-10-11 19:18

Re: 求教个脚本运行问题

#3

帖子 michaeldon » 2008-10-11 19:47

xiooli 写了:我运行没有错误阿。
我也不知道为什么,总是出现那个错误,是不是系统有什么错误呀
twwwater
帖子: 43
注册时间: 2008-08-17 6:09

Re: 求教个脚本运行问题

#4

帖子 twwwater » 2008-10-11 19:49

while [ -n "$1" ]; do????????
你是不是想
while [ -n "$1" ]
do
啊?
没有那个分号吧??????/
michaeldon
帖子: 7
注册时间: 2008-10-11 19:18

Re: 求教个脚本运行问题

#5

帖子 michaeldon » 2008-10-11 20:02

似乎是因为我写第二个HELP没顶格,真邪门
头像
solcomo
帖子: 2838
注册时间: 2007-04-25 13:12

Re: 求教个脚本运行问题

#6

帖子 solcomo » 2008-10-11 20:03

就是要顶格的
♜♞♝♛♚♝♞♜
♟♟♟♟♟♟♟♟
♙♙♙♙♙♙♙♙
♖♘♗♕♔♗♘♖

☠☯⚔⚓☣☦☃☕
☹☻☪☭☬⚖⚛⚜
ℜℳℬ™ ℋℯℓ℘ ℳℭ
sƂɐʍ рǀɹoʍ əɥʇ oS
twwwater
帖子: 43
注册时间: 2008-08-17 6:09

Re: 求教个脚本运行问题

#7

帖子 twwwater » 2008-10-12 11:48

好像是这样子的......
也没有怎么注意那一个地点.
这种程序好难找错误哦.....
回复