Hi,
On many occasions I have dealt with passing batch files arguments with spaces, quotes, percents, and slashes and all sorts of combinations of them. Usually I managed to figure out how to accomplish what I want, but this time I am stuck. I have tried a couple of hundred combinations now and my head is starting to hurt.
I’ve reduced the problem to a—fairly—simple requirement: pass from one batch file to another, an argument that contains some space-delimited text, one of which is a quoted space. That is, one batch file should pass some string X
to another so that the the second one echos "A "B C" D"
. I just can’t figure out what X
should be.
Here is a minimal batch file that demonstrates some attempts that do not work. (This BAT file takes the place of both by calling itself.)
::Goal is to print:
::"A "B C" D"
::ie., pass from one BAT file to another a quote containing spaces and a quote containing a space
@echo off
if not (%1)==() goto print
:passarg
call %0 "A "B C" D"
call %0 "A \"B C\" D"
%0 "A ""B C"" D"
:print
echo %1
pause
None of those attempts work. I’ve tried using "\" \""
, """ """
, """" """"
, "\"" "\""
, ""\" \"""
, "^" ^""
, ^"" "^"
, and so on. Either they print double double-quotes, lose everything after the space, or something else (that is wrong).
Any ideas? Thanks.