From owner-freebsd-questions@FreeBSD.ORG Sun Aug 24 20:42:48 2008 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 A664A1065670 for ; Sun, 24 Aug 2008 20:42:48 +0000 (UTC) (envelope-from derek@computinginnovations.com) Received: from betty.computinginnovations.com (mail.computinginnovations.com [64.81.227.250]) by mx1.freebsd.org (Postfix) with ESMTP id 60E258FC1B for ; Sun, 24 Aug 2008 20:42:44 +0000 (UTC) (envelope-from derek@computinginnovations.com) Received: from p28.computinginnovations.com (dhcp-10-20-30-100.computinginnovations.com [10.20.30.100]) (authenticated bits=0) by betty.computinginnovations.com (8.14.2/8.14.2) with ESMTP id m7OKgZpE032628; Sun, 24 Aug 2008 15:42:36 -0500 (CDT) (envelope-from derek@computinginnovations.com) Message-Id: <6.0.0.22.2.20080824153456.025ac978@mail.computinginnovations.com> X-Sender: derek@mail.computinginnovations.com X-Mailer: QUALCOMM Windows Eudora Version 6.0.0.22 Date: Sun, 24 Aug 2008 15:42:28 -0500 To: David Banning , questions@freebsd.org From: Derek Ragona In-Reply-To: <20080823101941.GA42601@skytracker.ca> References: <20080823101941.GA42601@skytracker.ca> Mime-Version: 1.0 X-Antivirus: avast! (VPS 080823-0, 08/23/2008), Outbound message X-Antivirus-Status: Clean X-Virus-Scanned: ClamAV 0.93.3/8081/Sun Aug 24 08:41:12 2008 on betty.computinginnovations.com X-Virus-Status: Clean X-ComputingInnovations-MailScanner-Information: Please contact the ISP for more information X-MailScanner-ID: m7OKgZpE032628 X-ComputingInnovations-MailScanner: Found to be clean X-ComputingInnovations-MailScanner-From: derek@computinginnovations.com X-Spam-Status: No Content-Type: text/plain; charset="us-ascii"; format=flowed X-Content-Filtered-By: Mailman/MimeDel 2.1.5 Cc: Subject: Re: space char shell script problem 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: Sun, 24 Aug 2008 20:42:48 -0000 At 05:19 AM 8/23/2008, David Banning wrote: >I am running into a problem with the space character in filenames. >For instance, If I want to run the script; > >for x in `ls` >do > echo $x >done > >then filenames that have a space in them ie: "john smith.jpg" >are processed by my script as two names, "john" and "smith.jpg". > >What is the best way to deal with this type of space problem in the shell? > >I know that file names in quotes solves some problems but I can't tranfer >that to my script. Depending on what your script is doing, I would use an intermediate file and awk. Something like: ls >/tmp/mytempfile cat /tmp/mytempfile | awk '{ print $0 }' if you are looking for something special add grep to the mix: cat /tmp/mytempfile | awk '{ print $0 }'|grep -i [some name pattern] rm /tmp/mytempfile You can save the results to another temporary file for more processing, or use awk more to create commandlines to execute in another script file such as: cat /tmp/mytempfile | awk '{ print $0 }'|grep -i [some name pattern] | awk '{printf"cp %s /backup/backupdir\n", $0)}' >/tmp/mycopyscript chmod +x /tmp/mycopyscript /tmp/mycopyscript So depending on what your original script was doing, this method may work for you. -Derek -- This message has been scanned for viruses and dangerous content by MailScanner, and is believed to be clean.