From owner-freebsd-questions@FreeBSD.ORG Fri Nov 9 04:53:15 2007 Return-Path: Delivered-To: questions@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id E0D5B16A420 for ; Fri, 9 Nov 2007 04:53:15 +0000 (UTC) (envelope-from dan@dan.emsphone.com) Received: from dan.emsphone.com (dan.emsphone.com [199.67.51.101]) by mx1.freebsd.org (Postfix) with ESMTP id 86F5513C4AC for ; Fri, 9 Nov 2007 04:53:15 +0000 (UTC) (envelope-from dan@dan.emsphone.com) Received: (from dan@localhost) by dan.emsphone.com (8.14.1/8.14.1) id lA94FecA072785; Thu, 8 Nov 2007 22:15:40 -0600 (CST) (envelope-from dan) Date: Thu, 8 Nov 2007 22:15:40 -0600 From: Dan Nelson To: =?utf-8?Q?Sd=C3=A4vtaker?= Message-ID: <20071109041540.GB72824@dan.emsphone.com> References: <4733CAB4.2080508@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <4733CAB4.2080508@gmail.com> X-OS: FreeBSD 7.0-BETA1 User-Agent: Mutt/1.5.16 (2007-06-09) Cc: questions@freebsd.org Subject: Re: problems using ls with for_in (SH) 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: Fri, 09 Nov 2007 04:53:16 -0000 In the last episode (Nov 08), Sdvtaker said: > Im trying to get a file with all the md5 hashes of one directory. My > initial script was this: > > #!/bin/sh > for file in $(ls) > do > echo $file > md5 $file > done > > The problem is with the file names who contains "whitespaces" becouse > the for_in passed each word as one iteration and not the full > filename, I'd tried using -B in ls, but doesnt help. There's no need to call ls at all. The shell can expand wildcards just fine by itself: for file in * do echo $file md5 $file done but in your case, since md5 can take multiple filenames on its commandline and prints the filename in its output: md5 * will suffice. -- Dan Nelson dnelson@allantgroup.com