免费注册 查看新帖 |

Chinaunix

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

请教C shell 中出现foreach: No match问题。如何解决!谢谢 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2011-09-07 17:32 |只看该作者 |倒序浏览
各位,这是csh程序
$DAT=/sbcimp/dyn/data/WM_COPSAU_DEV/dat/in/cops2wispa/aftcheck


foreach i ( $DAT/PC_FDE_2.temp* )
    /usr/bin/rm -f $i
end

如果$DAT路径下有PC_FDE_2.temp,PC_FDE_2.temp2等,命令运行正常,
但如果不存在PC_FDE_2.temp等,运行时提示foreach: No match的错误,并且foreach下的所有命令都没执行。

foreach语法有什么作用。要怎么改。谢谢。

论坛徽章:
0
2 [报告]
发表于 2011-09-07 17:50 |只看该作者
同志们。帮忙啊。

论坛徽章:
0
3 [报告]
发表于 2011-09-07 17:50 |只看该作者
不懂csh,纯支持帮顶

论坛徽章:
8
摩羯座
日期:2014-11-26 18:59:452015亚冠之浦和红钻
日期:2015-06-23 19:10:532015亚冠之西悉尼流浪者
日期:2015-08-21 08:40:5815-16赛季CBA联赛之山东
日期:2016-01-31 18:25:0515-16赛季CBA联赛之四川
日期:2016-02-16 16:08:30程序设计版块每日发帖之星
日期:2016-06-29 06:20:002017金鸡报晓
日期:2017-01-10 15:19:5615-16赛季CBA联赛之佛山
日期:2017-02-27 20:41:19
4 [报告]
发表于 2011-09-08 07:12 |只看该作者
foreach name (wordlist)
...
end

Successively sets the variable name to each member of wordlist and executes the sequence of commands between this command and the matching end. (Both foreach and end must appear alone on separate lines.) The builtin command continue may be used to continue the loop prematurely and the builtin command break to terminate it prematurely. When this command is read from the terminal, the loop is read once prompting with 'foreach? ' (or prompt2) before any statements in the loop are executed. If you make a mistake typing in a loop at the terminal you can rub it out.

论坛徽章:
0
5 [报告]
发表于 2011-09-10 01:33 |只看该作者
回复 1# cicarli


    你可以先通过(ls -ur $na/path/xxx.*)
然后检查 if ($status ==0) 来判断是否为空,从而防止foreach的错误。

论坛徽章:
3
2015年迎新春徽章
日期:2015-03-04 09:56:11数据库技术版块每日发帖之星
日期:2016-08-03 06:20:00数据库技术版块每日发帖之星
日期:2016-08-04 06:20:00
6 [报告]
发表于 2011-09-10 15:51 |只看该作者
就相当于for i in ......
do
....
done
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

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

清除 Cookies - ChinaUnix - Archiver - WAP - TOP