mahmood
mahmood

Reputation: 24755

foreach syntax in csh

For this csh script

#!/bin/csh

foreach file in (.)
  echo "$file"
end

I get this error

foreach: Words not parenthesized.

How can I fix that?

Upvotes: 3

Views: 15498

Answers (2)

Demis
Demis

Reputation: 5716

I found that csh was giving me issues splitting the files into their own iteration of $file (it would lump all the files into a single string with EOL's in between! Go figure...), so I had to use the following explicit call to ls:

foreach file ( `ls /path/to/directory/` )
    echo "/path/to/directory/$file"
end

Upvotes: 0

choroba
choroba

Reputation: 242038

There should be no in:

foreach file ( . )

Be sure to read Stop Using (and Teaching) C-Shell.

Upvotes: 6

Related Questions