Files containing " $ (and other) characters.

Hi everyone,

I’m here again with my UNIX question on MacScripter instead of some UNIX forum :rolleyes:

Yesterday I had some problems with moving files containing characters like ', $ etc.
That was because I used this kind of script:

do shell script "mv '" & SourceFile & "' '" & DestinationFolder

Which is the same as this script but only shorter:

do shell script "mv " & quoted form of SourceFile & " " & quoted form of DetinationFolder

These 2 scripts both have single quotes ( ’ ), using double quotes ( " ) allows you to move more files…
I tested:

set NotWorking to {}
repeat with i in {"\"", "'", "*", "$", "€", "%", "&", "é", "è", "!", "ç", "à ", "?", "-", "_", "(", ")", "=", "+"}
		do shell script "mkdir \"/My" & i & "s Folder\""
	on error
		set end of NotWorking to i as text
	end try
end repeat

It gave an error while I tried to make a folder containing a " , (or in AppleScript, escaped by a \ → ")
And a * in the file name didn’t gave an error but created a space instead of the *.

Are there work arounds? Are there (dis)advantages of using double quotes instead of single ones? And last but not least, are there other characters that will conflict ? (like the " ) when using double quotes?

I have to move them with shell script, no way I’ll use Finder to move files…

Thanks in advance

quoted form of is not the same as just writing single quotes.
Using quoted form of escapes also single quotes reliably.

I recommend to use always quoted form of

Oh, I didn’t know that… oops :slight_smile:

It does seem to work with all characters, is that correct?

Thank you :slight_smile:

Technical Note TN2065: do shell script in AppleScript

I was quite pleased when Apple added a link to that page under the do shell script command in the Standard Additions dictionary. (It’s also referenced in the Language Guide.)

Me too!

Ah, I didn’t know there was a difference…

Thanks for the info :slight_smile: