I always forget the foreach syntax. Here is a quick example that reads all the contents of a directory into an array, prints out the name of each file, runs a simple grep on it, and ends.
foreach i ( ` /bin/ls * ` )
foreach? echo $i
foreach?/bin/grep your_grep_string $i
foreach? end
This entry was posted
on Tuesday, January 17th, 2006 at 10:51 am and is filed under Data and Technology.
You can follow any responses to this entry through the RSS 2.0 feed.
You can leave a response, or trackback from your own site.

[...] If you have nested directories, you will need to incorporate foreach to recurse through and get all the directory names. [...]
gr8 link, help a lot, thanks….
[...] forgetting the syntax to make “for” loops in Bash. I guess it serves me right for using foreach most of my UNIX life instead. Anyhow, I know I will have to come back here to find it, so I thought [...]
Thanks a lot, men!
How I can write loop without nubmers but with some strings like ‘a’, ‘b’, ‘c’?
Thanks for the info! Very simple. Helps a lot