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: spiralbound.net » Using Sort to List Directories by Size

  2. Pingback: spiralbound.net » Bash For loop Example

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>