Batch file 多行命令中的批注释
我想知道是否可以在批处理文件命令中添加注释。具体来说,我有一个长Batch file 多行命令中的批注释,batch-file,sed,comments,multiline,Batch File,Sed,Comments,Multiline,我想知道是否可以在批处理文件命令中添加注释。具体来说,我有一个长SED命令,如下所示: @SED -r -e "s/.../.../"^ -e "s/.../.../"^ -e "s/.../.../"^ fileName >outFileName 我想对每个“-e”选项添加一条注释,如下例所示: :: Option #1: At the end of the line @SED -r -e "s/.../.../"^ // First comment -
SED
命令,如下所示:
@SED -r -e "s/.../.../"^
-e "s/.../.../"^
-e "s/.../.../"^
fileName >outFileName
我想对每个“-e”选项添加一条注释,如下例所示:
:: Option #1: At the end of the line
@SED -r -e "s/.../.../"^ // First comment
-e "s/.../.../"^ // Second comment
-e "s/.../.../"^ // Third comment
fileName >outFileName
:: Option #2: Between lines
@SED -r
@REM First comment
-e "s/.../.../"^
@REM Second comment
-e "s/.../.../"^
@REM Third comment
-e "s/.../.../"^
fileName >outFileName
有什么办法可以做到这一点吗?试试看。我没有sed,所以我只是用echo测试了一下
@echo off
:: Option #1: At the end of the line
echo SED -r -e "s/.../.../" %= First comment =%^
-e "s/.../.../" %= second comment =%^
-e "s/.../.../" %= third comment =%
:: Option #2: Between lines
echo SED -r^
%= First comment =%^
-e "s/.../.../"^
%= second comment =%^
-e "s/.../.../"^
%= third comment =%^
-e "s/.../.../"
pause
输出
SED -r -e "s/.../.../" -e "s/.../.../" -e "s/.../.../"
SED -r -e "s/.../.../" -e "s/.../.../" -e "s/.../.../"
Press any key to continue . . .
试试这个。我没有sed,所以我只是用echo测试了一下
@echo off
:: Option #1: At the end of the line
echo SED -r -e "s/.../.../" %= First comment =%^
-e "s/.../.../" %= second comment =%^
-e "s/.../.../" %= third comment =%
:: Option #2: Between lines
echo SED -r^
%= First comment =%^
-e "s/.../.../"^
%= second comment =%^
-e "s/.../.../"^
%= third comment =%^
-e "s/.../.../"
pause
输出
SED -r -e "s/.../.../" -e "s/.../.../" -e "s/.../.../"
SED -r -e "s/.../.../" -e "s/.../.../" -e "s/.../.../"
Press any key to continue . . .
*NIX版本的sed可以处理内联注释吗?*NIX版本的sed可以处理内联注释吗?如果注释包含
%
字符,有什么方法可以做到这一点吗?我想也许我可以把评论改成!=我的评论%=代码>因为我启用了延迟变量扩展,但这似乎不起作用。@JeffG,正确。延迟扩展在执行代码行时扩展变量。百分比变量在代码执行之前展开。逃脱%的唯一方法是加倍它。但在这种情况下,这对你来说是行不通的。只要没有定义每个结果变量,将注释中的括号加倍似乎是可行的。例如,%=%%不存在%%=%%
是有效的,因为未定义任何%=%%
、%不存在%
或%=%
。但是,%%=%%windir%%=%%
无效,因为定义了%windir%
。如果注释包含%%
字符,是否有方法执行此操作?我想也许我可以把评论改成!=我的评论%=代码>因为我启用了延迟变量扩展,但这似乎不起作用。@JeffG,正确。延迟扩展在执行代码行时扩展变量。百分比变量在代码执行之前展开。逃脱%的唯一方法是加倍它。但在这种情况下,这对你来说是行不通的。只要没有定义每个结果变量,将注释中的括号加倍似乎是可行的。例如,%=%%不存在%%=%%
是有效的,因为未定义任何%=%%
、%不存在%
或%=%
。但是,%%=%%windir%%=%%
无效,因为定义了%windir%
。