Date: Tue, 17 Aug 2010 08:22:17 -0700 From: Chip Camden <sterling@camdensoftware.com> To: FreeBSD Questions <freebsd-questions@freebsd.org> Subject: Re: Bash Script Help - File Names With Spaces Message-ID: <20100817152217.GF3974@libertas.local.camdensoftware.com> In-Reply-To: <4C6AA0FD.8000100@mykitchentable.net> References: <4C6AA0FD.8000100@mykitchentable.net>
next in thread | previous in thread | raw e-mail | index | archive | help
--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--
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20100817152217.GF3974>