November 28, 2007

Nifty C-Shell foreach script Trick for spaces with file names

This code did not work with files with spaces in the name:

  foreach i ( `find . -name '*.java'` )
    ls -l "$i"

This code did work:

  foreach ii ( `find . -name '*.java' | sed 's/ /@@@@/g'` )
    set i=`echo $ii | sed 's/@@@@/ /g'`
    ls -l "$i"

I was quite pleased - I almost resorted to using walk in Python - but that was averted. Somehow Sakai's assignments tool (in mid semester) changed the format of the "Download all for grading" ZIP file. I am sure it is an improvement - but it broke my C-Shell scripts I use for grading. Posted by csev at November 28, 2007 12:48 PM