From owner-freebsd-questions@FreeBSD.ORG Tue Aug 17 15:13:36 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 B043C1065679 for ; Tue, 17 Aug 2010 15:13:36 +0000 (UTC) (envelope-from drew@mykitchentable.net) Received: from smtp2.mc.surewest.net (qsmtp.mc.surewest.net [66.60.130.145]) by mx1.freebsd.org (Postfix) with SMTP id 86AD38FC0A for ; Tue, 17 Aug 2010 15:13:36 +0000 (UTC) Received: (qmail 20198 invoked from network); 17 Aug 2010 07:53:12 -0700 Received: by simscan 1.1.0 ppid: 20194, pid: 20195, t: 0.1822s 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 smtp2.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: v=1.0 c=1 a=ghY50JS3z9kA:10 a=VphdPIyG4kEA:10 a=8nJEP1OIZ-IA:10 a=jDt-9pEAAAAA:8 a=1t_qlkehnBZWoWqdp68A:9 a=Oy1NnTT7uvQjZgb1OiIA:7 a=270dVDJFWSeaoAo1mzNINUxO0K0A:4 a=wPNLvfGTeEIA:10 Received: from unknown (HELO blacklamb.mykitchentable.net) (69.62.230.77) by smtp2 with SMTP; 17 Aug 2010 07:53:12 -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 D4AB416492A for ; Tue, 17 Aug 2010 07:46:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=mykitchentable.net; s=default; t=1282056409; bh=8kJAxmswiJ4udi85mp85CQALCUuBFW8jIfIKfEGWBlQ=; h=Message-ID:Date:From:MIME-Version:To:Subject:Content-Type: Content-Transfer-Encoding; b=nM/1gw5TUxrwIwVRPzIzMtEsreq4JUwrzTye+UWezgoag/AxKPCrPDF2GD5RdVr17 1whbcXO57QkvCwmwXhChGXOMiDED1Pj+0tdbIqSZ7v1yYBJvbSzyHAykp7VYDM2RLg LdyL6Teqc7szAsqBKo3UMUvO1ezFz/NBkRPGyRUc= Message-ID: <4C6AA0FD.8000100@mykitchentable.net> Date: Tue, 17 Aug 2010 07:47:25 -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 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: Bash Script Help - File Names With Spaces 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:13:36 -0000 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? Thanks, Drew -- Like card tricks? Visit The Alchemist's Warehouse to learn card magic secrets for free! http://alchemistswarehouse.com