For loop in csh, tcsh

CSH has a for loop. The syntax of the loop is as follows

> foreach i (1,2,3,4,5)
     dosomething1
     dosomething2
  end

Another flavor of the foreach loop is when one wants to perform the same action on a set of files in a directory, or a set of sub-directories in a directory

Below is an example of copying a file verilog.v to bb.v in each of the sub-directories in the present directory

foreach fn ( `ls` )
  if (-d $fn) then
    cp $fn/Verilog/verilog.v $fn/Verilog/bb.v
  endif
end
Advertisements
For loop in csh, tcsh

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s