How can I check if an argument is defined when starting/calling a batch file?

后端 未结 7 1826
无人共我
无人共我 2020-12-13 03:21

I\'m trying to use the following validation logic in a batch file but the \"usage\" block never executes even when no parameter is supplied to the batch file.



        
7条回答
  •  北荒
    北荒 (楼主)
    2020-12-13 04:00

    IF "%~1"=="" GOTO :Usage
    

    ~ will de-quote %1 if %1 itself is quoted.

    " " will protect from special characters passed. for example calling the script with &ping

提交回复
热议问题