[prog] Bash script blues

Dan dan at cellectivity.com
Thu Aug 25 19:33:05 EST 2005


> for i in `ls -1 $HOUSE |grep .torrent` ; do mv "$i" `echo 
> "$i" |sed s/\ /_/g` ; done

The problem is in the "for" statement. The `ls -l ...` is evaluated to
to the string "this is torrent.torrent", which is then split at each
space.

The solution is to write it like this:

  for i in $HOUSE/*.torrent ; do ...

By the way, the statement looked correct to me as well. I had to do some
serious debugging to find the problem.

-- 
 I'm an idiot. At least this one [bug] took about 5 minutes to find.
         - Linus Torvalds




More information about the Programming mailing list