简体   繁体   中英

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?

There should be no in :

foreach file ( . )

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM