Date: Tue, 17 Aug 2010 08:28:40 -0700 From: Drew Tomlinson <drew@mykitchentable.net> To: FreeBSD Questions <freebsd-questions@freebsd.org> Subject: Re: Bash Script Help - File Names With Spaces -- SOLVED Message-ID: <4C6AAAA8.9030204@mykitchentable.net> In-Reply-To: <4C6AA0FD.8000100@mykitchentable.net> References: <4C6AA0FD.8000100@mykitchentable.net>
next in thread | previous in thread | raw e-mail | index | archive | help
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") <do stuff> 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
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?4C6AAAA8.9030204>