spaces in filename defeating xargs

Hi Folks-

I’ve having trouble with spaces in filenames- I’ve read up on ‘quoted form of POSIX’ but still getting errors.

	do shell script "find -X '/JobsX/#150,000-150,999/150001_PlanSponsor AD/FinalFile' \\( -name '150001_fnl.pdf' -o -name '150001_seps.pdf' -o -name '150001_callout*.pdf' \\) -print0 | xargs -0 -J {} cp {} ''/WamX/150001"

the space between ‘PlanSponsor’ and AD generates the error.

i compile the first path via a ‘quoted form of POSIX’, but this doesn’t matter.

any ideas? thanks!


Hi Ralph,

have you tried to escape the space(s) instead of using single quotes

do shell script "find -X /JobsX/#150,000-150,999/150001_PlanSponsor\\ AD/FinalFile \\( -name '150001_fnl.pdf' -o -name '150001_seps.pdf' -o -name '150001_callout*.pdf' \\) -print0 | xargs -0 -J {} cp {} ''/WamX/150001"

escaping the space with one \ or two \ does not work.


Hi Jaques-

in a cursory test, removing -X worked, but per the man page:

since i’m using xargs i’m wondering what is happening here…


I changed the script to see how the final string is compiling before it is executed

set theShell to "find -X '/JobsX/#150,000-150,999/150001_PlanSponsor AD/FinalFile' \\( -name '150001_fnl.pdf' -o -name '150001_seps.pdf' -o -name '150001_callout*.pdf' \\) -print0 | xargs -0 -J {} cp {} ''/WamX/150001"

And ran it. The final shell script is:

find -X ‘/JobsX/#150,000-150,999/150001_PlanSponsor AD/FinalFile’ \( -name ‘150001_fnl.pdf’ -o -name ‘150001_seps.pdf’ -o -name ‘150001_callout*.pdf’ \) -print0 | xargs -0 -J {} cp {} ‘’/WamX/150001

Does that look correct? I am not an expert in shell scripts but maybe someone else out there is. What do the double-backslashes do? Is that right?

thanks for the help Jaques- I never thought to question the manual.

Matt-boy- the \ is for escaping the space following it. From what I’ve read usually only one \ is required, but for some reason two \ seems to do the trick when calling a line command from AS. If anyone has an explanation for why two are needed, I’m curious!


Interesting! I haven’t seen that before.

Yeah, does anyone know what that is all about?

in AppleScript the backslash is a special character to escape characters like tab (\t), return (\r), linefeed (\n) and the backslash itself (\).
In a shell command line space characters are parameter separators. Space characters in parameters like a path must be wrapped in quotes e.g.

myComputer: ~ myuser$ /bin/ls '/Library/Application Support'

or escaped with a backslash

myComputer: ~ myuser$ /bin/ls /Library/Application\ Support

the AppleScript syntax of the second line is

do shell script "/bin/ls /Library/Application\\ Support"