How to escape spaces in the results of `mdfind`?

I'd like to find some file with mdfind and move it to another directory. So I tried like below but it makes an error caused by the space in the path.

> mdfind somefile.numbers 
/Users/hugh/Library/Mobile Documents/com~apple~Numbers/Documents/somefile.numbers
> mv $(!!) ~/Documents/
mv: rename /Users/hugh/Library/Mobile to /Users/hugh/Documents/Mobile: No such file or directory
mv: rename Documents/com~apple~Numbers/Documents/somefile.numbers
  to /Users/hugh/Documents/somefile.numbers: No such file or directory

So I tried to escape the space with printf %q, but it escapes everything.

> mv $(printf %q $(mdfind somefile.numbers)) ~/Documents/
mv: rename /Users/hugh/Library/MobileDocuments/com\~apple\~Numbers/Documents/somefile.numbers 
  to /Users/hugh/Documents/somefile.numbers: No such file or directory

There must be a good way to handle this but I cannot find one. Any ideas?


Solution 1:

Quote the variable:

mv "$(!!)" ~/Documents/