Re: OT: bash help

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 7 July 2013 20:18, Mike Wright <mike.wright@xxxxxxxxxxxxxx> wrote:
> 07/07/2013 12:03 PM, Steve Searle wrote:
>>
>> Around 07:29pm on Sunday, July 07, 2013 (UK time), Mike Wright scrawled:
>>
>>> I'm trying to write a bash command to transcode some videos into audios
>>> but am having trouble with filenames that contain spaces.
>>>
>>> ls *flv
>>>
>>> returns this:
>>>
>>> Jorge Drexler - Al otro Lado del Río.flv
>>>
>>> But in a bash for loop it doesn't work.
>>>
>>> for f in `ls *flv`; do echo $f; done
>>>
>>> returns this:
>>>
>>> Jorge
>>> Drexler
>>> -
>>> Al
>>> otro
>>> Lado
>>> del
>>> Río.flv
>>>
>>> Anybody know how to keep $f intact?
>>
>>
>> Look at the use of the IFS internal variable in bash and do something
>> like:
>>
>> IFS=$(echo -en "\n\b"); for f in `ls *flv`; do echo $f; done
>>
> exactly what I needed.  I'd never discovered IFS before
>
> all my youtube soundtracks can now move to google music!  woohoo!!!
>

As you've discovered, spaces in machineable filenames aren't great.
However for this case you may want to consider:
for F in *flv ; do echo "$F" ; done
The expanded *flv items are kept as single tokens. In fact this is why
"ls *flv" works to start with, it's the shell that expands the *
matches (globbing), not the ls command. ls just gets the separate file
names as arguments.


-- 
imalone
http://ibmalone.blogspot.co.uk
-- 
users mailing list
users@xxxxxxxxxxxxxxxxxxxxxxx
To unsubscribe or change subscription options:
https://admin.fedoraproject.org/mailman/listinfo/users
Guidelines: http://fedoraproject.org/wiki/Mailing_list_guidelines
Have a question? Ask away: http://ask.fedoraproject.org



[Index of Archives]     [Older Fedora Users]     [Fedora Announce]     [Fedora Package Announce]     [EPEL Announce]     [EPEL Devel]     [Fedora Magazine]     [Fedora Summer Coding]     [Fedora Laptop]     [Fedora Cloud]     [Fedora Advisory Board]     [Fedora Education]     [Fedora Security]     [Fedora Scitech]     [Fedora Robotics]     [Fedora Infrastructure]     [Fedora Websites]     [Anaconda Devel]     [Fedora Devel Java]     [Fedora Desktop]     [Fedora Fonts]     [Fedora Marketing]     [Fedora Management Tools]     [Fedora Mentors]     [Fedora Package Review]     [Fedora R Devel]     [Fedora PHP Devel]     [Kickstart]     [Fedora Music]     [Fedora Packaging]     [Fedora SELinux]     [Fedora Legal]     [Fedora Kernel]     [Fedora OCaml]     [Coolkey]     [Virtualization Tools]     [ET Management Tools]     [Yum Users]     [Yosemite News]     [Gnome Users]     [KDE Users]     [Fedora Art]     [Fedora Docs]     [Fedora Sparc]     [Libvirt Users]     [Fedora ARM]

  Powered by Linux