Batch file 结束语:|_|&引用;标记,多个“;后藤函数创建(cmd |.bat)
如何在1个脚本文件内,通过“for”循环中的快捷方式(“goto | anyth |“|”call | anyth |“|…”创建可访问的脚本 我的尝试:Batch file 结束语:|_|&引用;标记,多个“;后藤函数创建(cmd |.bat),batch-file,for-loop,cmd,Batch File,For Loop,Cmd,如何在1个脚本文件内,通过“for”循环中的快捷方式(“goto | anyth |“|”call | anyth |“|…”创建可访问的脚本 我的尝试: for /F %%a in ("t1") do ( if "%%a"=="" ( call :fsc ) else ( echo "n t" if "%%a"=="t1" ( call :fsc ) else (
for /F %%a in ("t1") do (
if "%%a"=="" (
call :fsc
) else (
echo "n t"
if "%%a"=="t1" (
call :fsc
) else (
call :fsc1
)
)
:fsc
echo t1
rem how? to end the :fsc (without the addition it continuing to "pause")
rem (answer: not possible in bash, this example's way can't be used because "goto" breaks out ?all scopes)
:fsc
echo t2
)
pause
还有另外一个
for /F %%a in ("t1") do (
if "%%a"=="" (
call :fsc
) else (
echo "n t"
if "%%a"=="t1" (
call :fsc
) else (
call :fsc1
)
)
)
:fsc
echo t1
goto :eof
:fsc1
echo t2
goto :eof
::why? after the "for" ends, execution doesn't coming here
:: (answer: all after "for" executed( including "goto :eof"))
pause
MintExtLimitMintExtLimitMintExtLimitm最佳实践是将调用的函数放在脚本的末尾。这与大多数人在其他脚本语言中所做的相反。函数是其他脚本语言中的函数,但它们在批处理文件中不是这样工作的。因此,在批处理文件中,最佳做法是将它们放在脚本的末尾
@ECHO OFF
for /F %%a in ("t1") do (
if "%%a"=="" (
call :fsc
) else (
echo "n t"
if "%%a"=="t1" (
call :fsc
) else (
call :fsc1
)
)
)
REM Put the main programming code here.
pause
REM END OF SCRIPT. ONLY FUNCTIONS BELOW.
GOTO :EOF
:fsc
echo t1
goto :eof
:fsc1
echo t2
goto :eof
不要在括号内的代码块中使用标签和
:
-stype注释!请注意,这与…@aschipfl,是的,你是对的,对不起,但是相关的问题,只是将它们插入本文中的错误,对于我来说,从代码注释中很明显,我知道如何“转到”,“调用”工作您可以在调用函数的末尾使用GOTO:EOF
将程序控制返回到调用该函数的代码行。@Squashman,我认为是这样,但它看起来不起作用,我尝试在第二个示例中使用它,它结束了整个文件的脚本,您说您知道Call
是如何工作的,但是你没有正确地使用它,原因已经告诉你了。我建议你适当地解释任务、实际投入和预期产出。大量的评论部分只强调了您的问题缺乏细节。从技术上讲,这只是关于在bash中使用start和end定义函数的可能性的问题,当然,我这边也有一些疏忽:)