[Gllug] Re: spaces and shell scripting

Jack Bertram jack at jbertram.net
Thu Sep 1 15:44:25 UTC 2005


* Jon Dye <jon at pecorous.co.uk> [050901 15:19]:
> Mick Farmer wrote:
> >Dear Jon,
> >
> >The GNU find command has a -print0 option to display file
> >names as NUL-terminated strings.  This should help.
> 
> I know, I used it in my example.  Can't work out how that helps to put 
> the filenames into a variable/array though, maybe I have to do something 
> with IFS?

In zsh, you could do something like this:


##start

IFS=$'\0'
FILES=($(find some/directory/ -print0))
unset IFS

if [ ${#FILES[@]} -eq 0 ]; then
  #do something
elif [ ${#FILES[@]} -eq 1 ]; then
  somecommand ${FILES[0]}
else
  i=0
  while [ $i -le ${#FILES[@]} ] 
  do
    othercommand ${FILES[$i]}
  done
fi

##end

(not tested)

I don't think you can specify a null character in IFS for bash, though I
could be wrong.

jack
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 196 bytes
Desc: not available
URL: <http://mailman.lug.org.uk/pipermail/gllug/attachments/20050901/90ada7e3/attachment.pgp>
-------------- next part --------------
-- 
Gllug mailing list  -  Gllug at gllug.org.uk
http://lists.gllug.org.uk/mailman/listinfo/gllug


More information about the GLLUG mailing list