How do I take a string giving a shell command line such as:
"program arg1 arg2 \"long argument with spaces\" arg\\\"3"
and turn it into a list of unquoted arguments like:
("program" "arg1" "arg2" "long argument with spaces" "arg\"3")
I.e. almost the reverse of shell-quote-argument
. shell-unquote-argument
doesn't do the trick.
I realize this sounds like an XY problem. I'd like to offer a minibuffer prompt for the user to give command line arguments to an external program, then run that program via call-process
. I could prompt for the command line arguments one at a time until the user gives a blank, but it seems like better UI to let them type all the arguments at once as they would at a real shell prompt. I could also error
out on fancy characters and only let them type alphanumerics, dashes and spaces, but that seems limiting. As a third alternative, I could use the call-process
variant that gives the command line to a shell instead using it directly as the argv, but I'd like to avoid giving the user the full power of the shell (pipes, redirects, etc.) as that would probably confuse more than help.