Csh中foreach执行命令的一个令人困惑的错误
该程序非常简单:
#!/bin/csh -f
foreach path ( fileA.txt fileB.txt )
wc -l $path
grep "test" $path
end
但是,输出是:
fileA.txt/wc: Not a directory.
fileA.txt/grep: Not a directory.
fileB.txt/wc: Not a directory.
fileB.txt/grep: Not a directory.
那么代码有什么问题以及正确的方法是什么?
The program is very simple:
#!/bin/csh -f
foreach path ( fileA.txt fileB.txt )
wc -l $path
grep "test" $path
end
However, the output is:
fileA.txt/wc: Not a directory.
fileA.txt/grep: Not a directory.
fileB.txt/wc: Not a directory.
fileB.txt/grep: Not a directory.
So what's wrong with the code and what's the correct way of doing it?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
切勿在 C-Shell 中使用 path 作为通用变量名,因为它包含 shell 查找命令程序的当前搜索目录。
这将比您的代码工作得更好:
You should never use path as a generic variable name in C-Shell since it contains the current search directories for the shell to find the command programs.
This will work much better than your code: