From owner-freebsd-questions@FreeBSD.ORG Tue Aug 17 15:28:04 2010 Return-Path: Delivered-To: freebsd-questions@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id AF1B110656E7 for ; Tue, 17 Aug 2010 15:28:04 +0000 (UTC) (envelope-from drew@mykitchentable.net) Received: from smtp1.mc.surewest.net (qsmtp.mc.surewest.net [66.60.130.145]) by mx1.freebsd.org (Postfix) with SMTP id 85E278FC08 for ; Tue, 17 Aug 2010 15:28:04 +0000 (UTC) Received: (qmail 17611 invoked from network); 17 Aug 2010 08:24:31 -0700 Received: by simscan 1.1.0 ppid: 17607, pid: 17608, t: 0.1823s scanners: regex: 1.1.0 attach: 1.1.0 spam: 3.1.7-deb X-Spam-Checker-Version: SpamAssassin 3.1.7-deb (2006-10-05) on smtp1.surewest.net X-Spam-Level: * X-Spam-Status: No, score=1.8 required=13.5 tests=RATWARE_GECKO_BUILD autolearn=disabled version=3.1.7-deb X-Spam-CMAE-Analysis: _CMAETAG_ Received: from unknown (HELO blacklamb.mykitchentable.net) (69.62.230.77) by smtp1 with SMTP; 17 Aug 2010 08:24:31 -0700 Received: from [127.0.0.1] (tagalong.mykitchentable.net [192.168.2.3]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by blacklamb.mykitchentable.net (Postfix) with ESMTPSA id E8D88164958 for ; Tue, 17 Aug 2010 08:28:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=mykitchentable.net; s=default; t=1282058882; bh=Nb87B+sR5qZ9VHsGtR1pHaY7gCYgdspgLVY+1VNSh60=; h=Message-ID:Date:From:MIME-Version:To:Subject:References: In-Reply-To:Content-Type:Content-Transfer-Encoding; b=HsytytAQAWsmzEtm5dpnQaf9RVr5JAJs0HTHpPn+gofjJYYMSwt/44zEB0oGvxyXX fh4qXBkh3PJIXFRotRjxYFmzbx3XNWCCLmfoBHUAQipSIb6DPEp6p1ukDslMV4RE6u e+/MNEzuHL2LB0/EmpQHUT70sLJzv/zZsfy1iE5g= Message-ID: <4C6AAAA8.9030204@mykitchentable.net> Date: Tue, 17 Aug 2010 08:28:40 -0700 From: Drew Tomlinson User-Agent: Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.1.11) Gecko/20100711 Thunderbird/3.0.6 MIME-Version: 1.0 To: FreeBSD Questions References: <4C6AA0FD.8000100@mykitchentable.net> In-Reply-To: <4C6AA0FD.8000100@mykitchentable.net> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Antivirus: avast! (VPS 100817-0, 08/16/2010), Outbound message X-Antivirus-Status: Clean Subject: Re: Bash Script Help - File Names With Spaces -- SOLVED 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: Tue, 17 Aug 2010 15:28:04 -0000 On 8/17/2010 7:47 AM, Drew Tomlinson wrote: > I have a collection of yearly top 100 Billboard mp3s in this format > (all one line - sorry if it wraps): > > /archive/Multimedia/Audio/Music/Billboard Top USA Singles/1980-028 > Kenny Loggins - This Is It.mp3 > > I want to create symbolic links to the top 30 in 1966-1969 in another > directory for easy migration to a flash card. Thus I invoked 'find' to > get a list (again, all one line): > > find -E "/archive/Multimedia/Audio/Music/Billboard Top USA Singles" > -regex '.*19[6-9][0-9]-0[0-2][0-9].*' > > (OK, I know this will only return the top 29) > > 'find' returns the complete filename as above: > > /archive/Multimedia/Audio/Music/Billboard Top USA Singles/1980-028 > Kenny Loggins - This Is It.mp3 > > Then I attempt to use 'basename' to extract the file name to a > variable which I can later pass to 'ln'. This seems to work: > > basename "/archive/Multimedia/Audio/Music/Billboard Top USA > Singles/1980-028 Kenny Loggins - This Is It.mp3" > > returns (all one line): > > 1980-028 Kenny Loggins - This Is It.mp3 > > which is what I would expect. However using it with 'find' give me > this type of unexpected result: > > for i in `find -E "/archive/Multimedia/Audio/Music/Billboard Top USA > Singles" -regex '.*19[6-9][0-9]-0[1-2][0-9].*'`; do basename "${i}";done > > 1980-028 > Kenny > Loggins > - > This > Is > It.mp3 > > Why is this different? And more importantly, how can I capture the > file name to $i? It finally occurred to me that I needed the shell to see a new line as the delimiter and not whitespace. Then a simple search revealed my answer: O=$IFS IFS=$(echo -en "\n\b") IFS=$O Sorry for the noise. Drew -- Like card tricks? Visit The Alchemist's Warehouse to learn card magic secrets for free! http://alchemistswarehouse.com