Foreach Example in tcsh

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

6 thoughts on “Foreach Example in tcsh

  1. Pingback: » Using Sort to List Directories by Size

  2. Pingback: » Bash For loop Example

Leave a Reply