免费注册 查看新帖 |

Chinaunix

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

文件统计有问题~~给小弟看看~~ [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2003-06-05 08:56 |只看该作者 |倒序浏览
#! /bin/bash
echo "the command will analysis all the c file in this directory"
echo "would you sure to execute the command ? [yes] to execute,[no] to exit"
read input
fileCnt=0
if [ $input="yes" ]; then
    fileCnt=`echo *.c | awk '{ print NF }'`
    #fileCnt=$(($fileCnt-1))
    echo "the total c file is $fileCnt"
    if [ "$fileCnt" -ge 1 ]; then
        if [ $RULECLANG="chinese" ]; then
           echo "the language is chinese"
           `find . -name "*.c" -print | xargs rulec >chinese`
        elif [ $RULECLANG="english" ]; then
           echo "the language is english"
           `find . -name "*.c" -print | xargs rulec > english`
        else
            echo "the language is japanese"
            `find . -name "*.c" -print | xargs rulec > japanese`
        fi
   else
       echo "there are no c files in the directory,please change the dir"
   fi
else
   echo "GoodBye"
fi
这个程序中,如果当前目录下没有.C文件的时候,fileCnt的值为什么是1呢?如果当前目录下有.C文件的时候,计算的就是对的,不明白的说~~给讲讲~

论坛徽章:
0
2 [报告]
发表于 2003-06-05 09:11 |只看该作者

文件统计有问题~~给小弟看看~~

因为你用的echo在没有.c文件时也有输出,所以awk必然报告1。
建议
fileCnt=`ls *.c|wc -l`

论坛徽章:
0
3 [报告]
发表于 2003-06-05 09:38 |只看该作者

文件统计有问题~~给小弟看看~~

原帖由 "muzx" 发表:
因为你用的echo在没有.c文件时也有输出,所以awk必然报告1。
建议
fileCnt=`ls *.c|wc -l`
   
哦,俺明白了,原来如北啊~~原来"厕所" "wc"也这么好用啊~~都是经验啊~
3X~~

论坛徽章:
0
4 [报告]
发表于 2003-06-06 09:20 |只看该作者

文件统计有问题~~给小弟看看~~

可以直接在 一些环境配置文件中例如 .kshrc
以后可以直接使用


  1. alias   ls="ls -FC" \
  2.           ll="ls -la" \
  3.           rm="rm -i"\
  4.           ld="ls -l |grep ^d"\
  5.           c="tput clear"\
  6.           l="ls |wc -w"
复制代码
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

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

清除 Cookies - ChinaUnix - Archiver - WAP - TOP