免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 3505 | 回复: 2
打印 上一主题 下一主题

[文本处理] case 语句执行报错syntax error near unexpected token [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2014-04-09 10:46 |只看该作者 |倒序浏览
新人学习shell,写了一个创建指定目录,并将某个目录下的指定文件拷贝到该目录下的脚本,不过运行时出现如下错误
copy_file.sh: line 20: syntax error near unexpected token `$is_postive'
copy_file.sh: line 20: `     case $is_postive in'
这第20行这个变量is_postive到底哪儿有问题,各位大神帮忙看下哈

#!/bin/sh

input_num(){
if [ $# -ne 1 ]
then
echo "arguments error"
fi

num=""

while :
do
read _num
is_postive=`echo ${_num}|sed 's/[0-9]//g'|awk '{print length($0)}'`
if [ $_num -ne 0 ]
then
     case "$is_postive" in
     1)
       echo "your input is not a positive integer,please input a positive integer";num="";;
     case "$is_postive" in
     0)
       num=${_num};break;;
     *)
       echo "unknown error,please input a positive integer again";num="";;
     esac
else
echo "your input number is zero,please input a positive integer"
fi
done

export num
return 0
}

input_num "please input the counts of dictionaries you want to create and copy"

if [ -d $HOME/aa ]
then
rm -rf $HOME/aa
fi

count="0"
while [ $count -lt $num ]
do
   count =`echo $((count + 1))`
   mkdir -p $HOME/aa/bb/ch${count} > /dev/null 2>&1
   if [ $? -ne 0 ]
     then echo "create dictionary ch${count} failed,please check it";continue
   fi
   
   for i in chm doc xls html
   do
     if [ -f $HOME/*.${i} ] && [ -d $HOME/aa/bb/ch${count} ]
         then
           cp $HOME/*.${i} $HOME/aa/bb/ch${count} > dev/null 2>&1
           if [ $? -ne 0 ]
           then
             echo "copy $HOME/*.${i} to $HOME/aa/bb/ch${count} failed"
           else
             echo "copy ${i} to ch${count} successful"
           fi
         elif [ ! -f $HOME/*.${i} ]
     then
            echo "the ${i} files are not exit"
         elif [ ! -d $HOME/aa/bb/ch${count} ]
     then
        echo "$HOME/aa/bb/ch${count} is not exit"
     else
           echo "unkown error"
         fi
   done
done

论坛徽章:
0
2 [报告]
发表于 2014-04-09 10:48 |只看该作者
感觉是
0)上面那行多了个case

论坛徽章:
0
3 [报告]
发表于 2014-04-09 10:53 |只看该作者
的确是这个问题,语法没过关啊 多谢了回复 2# runintostar


   
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP