[clug] Help with bash script

Duncan Roe duncan_roe at acslink.net.au
Sun Nov 2 05:06:30 GMT 2008


With regard to spaces in file names and find | xargs, I have found the following
to work:

  find . -type f -print | sed -e 's/ /\\ /g' | xargs whatever

Without this, xargs will indeed see multiple arguments from a single file name
containing spaces. It is very much more efficient to use xargs than to use
find's -exec.

Cheers ... Duncan.

On Sat, Nov 01, 2008 at 07:34:44PM +1100, Alastair D'Silva wrote:
> > Well one thing to do as a start is this: (to take care of spaces).
> >
> >   mv "${file}" ${i}
>
> Not quite everything you need . . . the for loop will still get tripped up
> on spaces. Shell expansion will expand the wildcard into a space separated
> list of files, which for will then split on spaces.
>
> Instead of the for loop, you want to use:
> find -exec <script>
> This will pass the filename as the first parameter to the script, which can
> then track state itself by storing it in an additional file.
>
> or
>
> find -print0 | xargs -0 -n 10 <script> (GNU find & xargs only)
> This will pass in 10 files at a time as parameters to the script.
>
> Of course, within the script, you should enclose the variables in double
> quotes as above.
>
> --
> Alastair D'Silva           mob: 0423 762 819
> Networking Consultant
> New Millennium Networking  web: http://www.newmillennium.net.au
> skype: alastair_dsilva     msn: alastair at d-silva.org
> blog: http://alastair.d-silva.org
>
> --
> linux mailing list
> linux at lists.samba.org
> https://lists.samba.org/mailman/listinfo/linux

--
 Please avoid sending me Word or PowerPoint attachments.
 See http://www.gnu.org/philosophy/no-word-attachments.html


More information about the linux mailing list