I think the problem with the OP was that he wants to make BOTH of the following:
- Pass a parameter that may contain spaces
- Check if parameter is missing
As mentioned by several posters, to pass a parameter containing spaces, you must surround the actual value of the parameter with double quotes.
To check if a parameter is missing, the method I always studied was:
if "%1" == ""
However, if the actual parameter is specified (as it should be, if the value contains spaces), it becomes
if ""actual parameter value"" == ""
which causes an "unexpected" error. If you use
if %1 == ""
then the error no longer occurs for quoted values. But in this case, the test no longer works when the value is missing - it becomes
if == ""
To fix this, use any other characters (except for characters with a special value for DOS) instead of quotation marks in the test:
if [%1] == [] if .%1. == .. if abc%1xyz == abcxyz
May 05, '09 at 16:29 2009-05-05 16:29
source share