From owner-freebsd-questions@FreeBSD.ORG Wed Dec 14 17:48:44 2005 Return-Path: X-Original-To: freebsd-questions@freebsd.org Delivered-To: freebsd-questions@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 2B44716A424 for ; Wed, 14 Dec 2005 17:48:44 +0000 (GMT) (envelope-from freebsd-questions@amadeus.demon.nl) Received: from post-24.mail.nl.demon.net (post-24.mail.nl.demon.net [194.159.73.194]) by mx1.FreeBSD.org (Postfix) with ESMTP id F350243D5D for ; Wed, 14 Dec 2005 17:48:42 +0000 (GMT) (envelope-from freebsd-questions@amadeus.demon.nl) Received: from amadeus.demon.nl ([82.161.18.200]:55839 helo=[10.0.1.2]) by post-24.mail.nl.demon.net with esmtp (Exim 4.51) id 1Emak5-0001xD-Do; Wed, 14 Dec 2005 17:48:41 +0000 Mime-Version: 1.0 (Apple Message framework v746.2) In-Reply-To: References: Content-Type: text/plain; charset=US-ASCII; delsp=yes; format=flowed Message-Id: <7E787746-B0C0-4CBD-B9D1-4E348C638B76@amadeus.demon.nl> Content-Transfer-Encoding: 7bit From: freebsd-questions Date: Wed, 14 Dec 2005 18:48:37 +0100 To: user , FreeBSD Questions X-Mailer: Apple Mail (2.746.2) Cc: Subject: Re: I need a better way to loop in the shell... X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 14 Dec 2005 17:48:44 -0000 On 14 dec 2005, at 05:44, user wrote: > > I always do loops in /bin/sh like this: > > for f in `cat file` ; do rm -rf $f ; done > > Easy. I like doing it like this. > > The problem is, when I am dealing with an input list that has multiple > words per line, this chops it up and treats every word as a new > line... > > For instance, lets say I have a file full of filenames, like this: > > # cat file > > 10,000 Maniacs MTV Unplugged - 01 - These Are Days.mp3 > 10,000 Maniacs MTV Unplugged - 02 - Eat For Two.mp3 > 10,000 Maniacs MTV Unplugged - 03 - Candy Everybody Wants.mp3 > > and I try to use the above loop on it, it thinks that every word is > a line > ... the above loop will attempt to delete the following files: > > 10,000 > Maniacs > MTV > Unplugged > - > 01 > - > These > > (and so on) > > Even if I quote the variable $f, like: > > for f in `cat file` ; do rm -rf "$f" ; done > > it still does the same thing. > > ----- > > So my question is, what is a nice simple way to loop in the shell, as > close to what I am doing above as possible, that does not have this > problem ? Should I just be using something other than `cat` ? Or > what ? > > THanks. > You can also try to store "cat file" into a variable: #!/bin/sh V=`cat file` for f in $V ; do rm -rf $f ; done Arno