[prog] Bash script blues

Kathryn Hogg kjh at flyballdogs.com
Fri Aug 26 00:15:07 EST 2005


Jacinta Richardson said:
> If you want a solution to make the problem away I can help you with that.
> If
> you want to know why your above code isn't working, I can't help so much.
> If
> you try:
>
> 	for i in `ls -1 | grep .torrent`; do echo "$i"; done;
>
> you'll find that what the for loop is giving you is
>
> 	this
> 	foo
> 	it.torrent
> 	this_that_torrent.torrent
>
> which isn't a good thing at all.  I don't know how to make the for loop
> behave itself.

I would just do

for i in *.torrent
do
  echo $i
done

Which is actually better since it only matches files ending in .torrent. 
The original way would return every file with .torrent any where in the
name.


>
> I also can't make:
>
> 	echo "$i" | sed s/\ /_/g

echo "$i" | tr '[:blank:]' '_'

should do the trick

-- 
Kathryn
http://womensfooty.com



More information about the Programming mailing list