Create a shell-escaped POSIX path in macOS
问题 I need to create a string from a full POSIX path (starting at the root), so that it could be pasted directly into a Unix shell like bash , e.g. in Terminal.app , without the need for quotes around the path. (I do not actually pass the string to a shell, but instead need it for passing it to another program. That program expects the path in just the form that you get when you drag a file into Terminal.app .) For that, I need to escape at least any spaces in the string, by prepending them with