You can use grep
or egrep
rather than a file matching pattern:
foreach dir ( `ls | egrep '^(i686\|amd64)\.'` )
# commands
end
If no files match, the ls | egrep ...
command simply won't produce any output, and the body of your loop won't execute.
Given the name dir
, you might want to add a test that any matching file name is actually a directory.
An uglier alternative is to temporarily create a matching file:
tmp=i686.$$
mkdir $tmp
foreach dir (i686.* amd64.*)
if ($dir != $tmp) then
# commands
endif
end
rm $tmp
I don't necessarily recommend this.
You might want to use a :q
suffix or add double quotes if you need to worry about directory names containing funny characters.