簡體   English   中英

windows bat文件不能注釋掉這個

[英]windows bat file cannot comment out this

我正在嘗試注釋掉一些有用的提示。 我按照這個 Stack Overflow 頁面應用了最具防御性的評論 - 使用雙引號。 評論錯誤 但我仍然收到錯誤

這是我的簡單腳本:test_comment.cmd

@echo off

:: "   %~nI        - expands %I to a file name only "
:: "   %~xI        - expands %I to a file extension only "
for /F "delims=" %i in ("c:\foo\bar baz.txt") do @echo %~nxi

這是我運行時遇到的錯誤

>test_comment
The following usage of the path operator in batch-parameter
substitution is invalid: %~nI        - expands %I to a file name only "


For valid formats type CALL /? or FOR /?
The syntax of the command is incorrect.

如果我刪除了這兩條注釋行,錯誤就會消失; 這樣我就知道評論沒有用。

我應該如何注釋掉這兩行?

我真的不想刪除它們。

我正在使用 windows 10,最新補丁,默認 cmd.exe。

我按照@Stephan 評論中的鏈接閱讀: Batch Line Parser

階段 0) 讀取線:

階段 1) 擴張百分比:

階段 2) 處理特殊字符、標記化並構建緩存的命令塊

簡而言之:在第 1 階段的百分比擴展之后,在第 2 階段解析注釋。

解決方案:按照@Magoo 在評論中的建議,使用 % 轉義評論中的 %。

@echo off

:: "   %%~nI        - expands %%I to a file name only "
:: "   %%~xI        - expands %%I to a file extension only "
for /F "delims=" %%I in ("c:\foo\bar baz.txt") do @echo %%~nxI

然后我得到了想要的結果

>test_comment
bar baz.txt

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM