我有这样的 .bat 代码。例如:
@ECHO OFF
setlocal EnableDelayedExpansion
call :setESC
set arg1=%1
set "noArgs=true"
for %%a in (%*) do (
if not %%a == "" (
:: if it is not empty arguments.
set "noArgs=false"
)
)
if "%noArgs%" == "true" (
if "%arg1%" == "" (
:: it is empty args AND argument1 (/arg) is empty
:: set default argument here. <-----------
set "%%1=build"
)
)
:: for debugging.
echo all args: %* :end.
:: run external command (gulp).
gulp --cwd "/my/project" %*
gulpbat.bat
在 CLI 中,如果我输入命令gulpbat build
,它将调用gulp build
. 但是如果我打电话gulpbat
,它将是响应Task never defined: default。
build
如果命令行中缺少默认任务,我想添加默认任务并将%*
自动使用。
我已经尝试过这些但失败了。
set "%1=build" :: error: The syntax of the command is incorrect.
set "%~1=build" :: error: The syntax of the command is incorrect.
set "%%1=build" :: not working in %*
1 个回答