From owner-freebsd-questions@FreeBSD.ORG Tue Aug 17 15:22:23 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 CB2C010656A4 for ; Tue, 17 Aug 2010 15:22:23 +0000 (UTC) (envelope-from sterling@camdensoftware.com) Received: from wh2.interactivevillages.com (wh2.interactivevillages.com [75.125.250.34]) by mx1.freebsd.org (Postfix) with ESMTP id 93F178FC08 for ; Tue, 17 Aug 2010 15:22:23 +0000 (UTC) Received: from 174-21-101-5.tukw.qwest.net ([174.21.101.5] helo=_HOSTNAME_) by wh2.interactivevillages.com with esmtpsa (TLSv1:AES256-SHA:256) (Exim 4.69) (envelope-from ) id 1OlNlI-00011S-Ev for freebsd-questions@freebsd.org; Tue, 17 Aug 2010 08:07:37 -0700 Received: by _HOSTNAME_ (sSMTP sendmail emulation); Tue, 17 Aug 2010 08:22:17 -0700 Date: Tue, 17 Aug 2010 08:22:17 -0700 From: Chip Camden To: FreeBSD Questions Message-ID: <20100817152217.GF3974@libertas.local.camdensoftware.com> Mail-Followup-To: FreeBSD Questions References: <4C6AA0FD.8000100@mykitchentable.net> Mime-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="j2AXaZ4YhVcLc+PQ" Content-Disposition: inline In-Reply-To: <4C6AA0FD.8000100@mykitchentable.net> User-Agent: Mutt/1.4.2.3i Company: Camden Software Consulting URL: http://camdensoftware.com X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - wh2.interactivevillages.com X-AntiAbuse: Original Domain - freebsd.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - camdensoftware.com Subject: Re: 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:22:24 -0000 --j2AXaZ4YhVcLc+PQ Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable Quoth Drew Tomlinson on Tuesday, 17 August 2010: > I have a collection of yearly top 100 Billboard mp3s in this format (all= =20 > one line - sorry if it wraps): >=20 > /archive/Multimedia/Audio/Music/Billboard Top USA Singles/1980-028 Kenny= =20 > Loggins - This Is It.mp3 >=20 > I want to create symbolic links to the top 30 in 1966-1969 in another=20 > directory for easy migration to a flash card. Thus I invoked 'find' to=20 > get a list (again, all one line): >=20 > find -E "/archive/Multimedia/Audio/Music/Billboard Top USA Singles"=20 > -regex '.*19[6-9][0-9]-0[0-2][0-9].*' >=20 > (OK, I know this will only return the top 29) >=20 > 'find' returns the complete filename as above: >=20 > /archive/Multimedia/Audio/Music/Billboard Top USA Singles/1980-028 Kenny= =20 > Loggins - This Is It.mp3 >=20 > Then I attempt to use 'basename' to extract the file name to a variable= =20 > which I can later pass to 'ln'. This seems to work: >=20 > basename "/archive/Multimedia/Audio/Music/Billboard Top USA=20 > Singles/1980-028 Kenny Loggins - This Is It.mp3" >=20 > returns (all one line): >=20 > 1980-028 Kenny Loggins - This Is It.mp3 >=20 > which is what I would expect. However using it with 'find' give me this= =20 > type of unexpected result: >=20 > for i in `find -E "/archive/Multimedia/Audio/Music/Billboard Top USA=20 > Singles" -regex '.*19[6-9][0-9]-0[1-2][0-9].*'`; do basename "${i}";done >=20 > 1980-028 > Kenny > Loggins > - > This > Is > It.mp3 >=20 > Why is this different? And more importantly, how can I capture the file= =20 > name to $i? Try: find -E ... | while read i; do; basename $i; done When using back-ticks, all the output gets appended together, space-separated. Then 'for' can't tell the difference between a space in a filename and a delimiter. Using 'read' instead preserves line boundaries. >=20 > Thanks, >=20 > Drew >=20 > --=20 > Like card tricks? >=20 > Visit The Alchemist's Warehouse to > learn card magic secrets for free! >=20 > http://alchemistswarehouse.com >=20 > _______________________________________________ > freebsd-questions@freebsd.org mailing list > http://lists.freebsd.org/mailman/listinfo/freebsd-questions > To unsubscribe, send any mail to "freebsd-questions-unsubscribe@freebsd.o= rg" --=20 Sterling (Chip) Camden | sterling@camdensoftware.com | 2048D/3A978E4F http://camdensoftware.com | http://chipstips.com | http://chipsquips= .com --j2AXaZ4YhVcLc+PQ Content-Type: application/pgp-signature Content-Disposition: inline -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.10 (FreeBSD) iQEcBAEBAgAGBQJMaqkpAAoJEIpckszW26+R57MIAIow17T67uJRNPRqAPN1/Het 5FTpH0u0vMZuQsrTTFwsaeQcAhlu4j+24EdZ0A4oyYs7MWpzWtDmmJpXNljehBwB Nshurxwp+aKtVfiHPC/e9p73aMEmEfCrU7mTOVe4X9zKZ1cZyBBH0arbpLjcBHxu gt0NmJz9KRuPadUrQWu3MkL9YsFOre0G70NKbMmVTIidoi4qvhblxvwJNkCdzb+4 sT1McNI63zHX3y10jjnFyF9sNLGSeckDrrgABteSlHV7UAxUsPUonF9a3/xGsPyv am2VMkmZzrPn5NQACJYKq0qIvt8T0FWSFiL3V9G6A/6VCH6MsYN6jSBkGp0iEEA= =j5OQ -----END PGP SIGNATURE----- --j2AXaZ4YhVcLc+PQ--