Re: Help with files and spaces with shell script

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

 



On 9/16/07, Skunk Worx <skunkworx@xxxxxxxxxxx> wrote:
> Paul Ward wrote:
> >> But pretending ctime is creation time, which may be close enough for
> >> your purposes:
> > You're right ctim eis not creation but is close enough for my script
> >
> >>   find /myth/recordings/ -maxdepth 1 -name \*.mpg -ctime -1 ! -mtime -1 -print
> > I did not know you could use the ! that saves one line of code ;o)
> >
> > My script so far looks like this,can someone help me on one issue.
> >
> > If a file name has a space then the script goes wrong as it interprets
> > each word as a file, I thought that putting the variable into quotes
> > would fix this but it did not, what is the answer please.
> >
> > for i in `find /myth/recordings/ -maxdepth 1 -name \*.mpg -ctime -1 !
> > -mmin -1 -print`
> >  do
> >    /usr/bin/mencoder "$i" -ovc xvid -oac mp3lame -xvidencopts
> > bitrate=800 -o $TMP/tmp.mpg > $TPM/enc_errors 2>&1 && cp -fv
> > $TMP/tmp.mpg "$i"
> >  done
> >
> > Thanks
> >
>
> Change IFS to nothing (<cr>) before the call to 'for in find...'
>
> e.g;
>
> IFS=
> for i in `find...
>
> ---
> John
>
> --
> fedora-list mailing list
> fedora-list@xxxxxxxxxx
> To unsubscribe: https://www.redhat.com/mailman/listinfo/fedora-list
>
You beat me to it.

Use the following in your script

ORIGINAL_IFS=$IFS #save default individual field separator
IFS=$'012'  # set individual field separator to ASCII hex character
12, being newline.

By setting the individual field separator to newline, it looks for a
new line for the next field.  This allows files with spaces to work
properly.

At the end of the script you put

IFS=$ORIGINAL
to restore the IFS to what it was when the script started.

Jacques B.

-- 
fedora-list mailing list
fedora-list@xxxxxxxxxx
To unsubscribe: https://www.redhat.com/mailman/listinfo/fedora-list
[Index of Archives]     [Older Fedora Users]     [Fedora Announce]     [Fedora Package Announce]     [EPEL Announce]     [Fedora Magazine]     [Fedora News]     [Fedora Summer Coding]     [Fedora Laptop]     [Fedora Cloud]     [Fedora Advisory Board]     [Fedora Education]     [Fedora Security]     [Fedora Scitech]     [Fedora Robotics]     [Fedora Maintainers]     [Fedora Infrastructure]     [Fedora Websites]     [Anaconda Devel]     [Fedora Devel Java]     [Fedora Legacy]     [Fedora Desktop]     [Fedora Fonts]     [ATA RAID]     [Fedora Marketing]     [Fedora Management Tools]     [Fedora Mentors]     [SSH]     [Fedora Package Review]     [Fedora R Devel]     [Fedora PHP Devel]     [Kickstart]     [Fedora Music]     [Fedora Packaging]     [Centos]     [Fedora SELinux]     [Fedora Legal]     [Fedora Kernel]     [Fedora OCaml]     [Coolkey]     [Virtualization Tools]     [ET Management Tools]     [Yum Users]     [Tux]     [Yosemite News]     [Gnome Users]     [KDE Users]     [Fedora Art]     [Fedora Docs]     [Asterisk PBX]     [Fedora Sparc]     [Fedora Universal Network Connector]     [Libvirt Users]     [Fedora ARM]

  Powered by Linux