do shell script - quoted form white space issues

Tearing my hair out on this one -
Im trying to move files, but because of white space in the volume name the mv shell is barfing.
Im running “quoted form of POSIX path of” on relevant paths, but its not taking it.

Interestingly I can make the target directory just fine with

mkdir -p '/Volumes/ComDes DropBox/YourDesktopClutter/Files_2013-02-13_19-12-13/Movies'

Where as this fails:

mv '/Users/comdesadmin/Movies/*' '/Volumes/ComDes DropBox/YourDesktopClutter/Files_2013-02-13_19-12-13/Movies'

If I manually strip the quotes and ‘\’ out the white space it works fine through terminal.

Anyone have a magic bullet here?
Many thanks in advance.


set destinationFolderPath to "/Volumes/ComDes DropBox/YourDesktopClutter/" as string
set destinationFolderName to ("Files_" & (do shell script "date '+%Y-%m-%d_%H-%M-%S'")) as string -- Create daily parent folder
set destinationFolderPath to destinationFolderPath & destinationFolderName as string
set makedir to "mkdir -p" -- make the dir
set moveFiles to "mv -p"
set sourceFolders to {"Movies", "Pictures", "Music"}
set myUser to (path to home folder from user domain) as string
tell application "Finder"
	repeat with sourceFolder in sourceFolders
		set testSource to (POSIX path of myUser) & sourceFolder as string
		--log testSource
		set sizeTest to size of (info for testSource)
		if sizeTest is greater than or equal to 0 then
			
			do shell script "mkdir -p" & space & quoted form of (destinationFolderPath & (POSIX path of sourceFolder)) -- make directory
			tell application "Finder" to set the clipboard to ("mv" & space & quoted form of (testSource & "/*") & space & quoted form of (destinationFolderPath & (POSIX path of sourceFolder))) as text
			do shell script "mv -f" & space & (quoted form of (testSource & "/*")) & space & quoted form of (destinationFolderPath & "/" & sourceFolder & "/")
			-- results in: mv '/Users/comdesadmin/Movies/*' '/Volumes/ComDes DropBox/YourDesktopClutter/Files_2013-02-13_18-57-43/Movies' - does not work?!
		end if
	end repeat
end tell

Browser: Safari 537.17
Operating System: Mac OS X (10.8)

humm just discovered that unquoting the first path works:

mv /Users/comdesadmin/Movies/* '/Volumes/ComDes DropBox/YourDesktopClutter/Files_2013-02-13_19-12-13/Movies'

This is a step in the right direction, but I dont know if the source path will NEVER have whitespace in it. . . . Is this a bug?

Hi,

put the asterisk out of the quotation


quoted form of (testSource & "/") & "*"

wow that was painful - better part of an afternoon.

I couldn’t find this anywhere in the documentation - how did you know??

When you type in the command line


cp -R '~/Desktop/*' .

you get an No such file or directory error, so it’s logical that you must not quote the wildcard

It is well described in the documentation of bash itself.

bash manual about pathname expansion

bash about quoting (read that it says that expansions are turned off as well)

As you can see, if something went wrong on the command line, mis-interpretation, it’s better to read the documentation about bash.