0

I've a shellscript, that I run from an NSTask, that I build dynamically. Everything works fine besides one thing:

If the filename contains a blank, it's ignored by the find-command. I use it like that: 'find -iname *.xxx'.

If the filename looks something like 'aaa bbb.xxx', than it's not found.

Any help appreciated.

Regards, Marcus

Marcus Toepper
  • 2,403
  • 4
  • 27
  • 42

2 Answers2

0

find does not care if your file names have spaces in them. That's not your problem.

If you're actually calling it as typed in your question (find -iname *.xxx), then the problem is that you need to quote the file name pattern to protect it from shell expansion: find -iname '*.xxx'. Note the quotes around the pattern; they're essential.

Otherwise, the problem is very likely in how you're handling the file names you're getting back. For example, this won't work:

for f in `find -iname '*.xxx'`; do
   echo "file: $f"
done

you'll see that the backtick operator actually splits on spaces (or, $IFS, actually) and you get back two "files": 'aaa' and 'bbb.xxx'.

derobert
  • 49,731
  • 15
  • 94
  • 124
  • The `-print0` option to `find` might be useful here. Note that it requires some extra work in whatever processes the output of `find`. – Keith Thompson Oct 08 '11 at 07:57
  • @KeithThompson: Yep, often does. And if the "whatever process" is the rest of the shell script, then http://stackoverflow.com/questions/1116992/capturing-output-of-find-print0-into-a-bash-array – derobert Oct 08 '11 at 08:09
0

Escape the Pattern like this:

find -iname '*.xxx' -print

please consider +1 if it helped. thanks

Franz Bettag
  • 437
  • 2
  • 8