A confusing error of executing commands in foreach in Csh
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 开发者_StackOverflow社区code and what's the correct way of doing it?
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:
#!/bin/csh -f
foreach mypath ( fileA.txt fileB.txt )
wc -l $mypath
grep "test" $mypath
end
精彩评论