[英]How does echo off and on are executes in same batch script?
echo off 和 on 如何在下面的腳本中工作,如果我們想在批處理腳本的某些地方使用echo off
讓我們說外部循環和內部循環echo on
我們應該怎么做
如果我嘗試使用@
而不是全局使用@echo off
將其關閉。我必須在每一行中放置“@”嗎?
這里是以下代碼:
@echo off
set select=package:com.google.ar.core
set "str=%select%"
set "string1=%str::=" & set "string2=%"
@echo on
echo %select%
echo %string2%
@echo off
echo.
output 的外觀如下
echo package:com.google.ar.core
package:com.google.ar.core
echo com.google.ar.core
com.google.ar.core
請幫助理解執行
首先是基本點:您需要區分在批處理文件中執行命令時回顯命令與命令的 output 之間的區別。 命令的 output 是命令生成的內容,它始終顯示在屏幕上(除非有 output 重定向,但這是另一回事)。
“命令的回聲”是對將要執行的命令的跟蹤。 如果“echo is on”,則命令本身將在執行之前顯示。
如果“echo is on”,如果您在命令前面加上@
,則可以取消命令的回顯。
您應該注意,命令的回顯發生在命令被解析時,即在執行前被審查,並且括號中的幾個命令被作為一個整體解析。 這意味着更改代碼塊內的“回顯”狀態不會影響塊中的命令:回顯將具有與塊開始時相同的狀態。 當然,如果在塊中改變了回顯狀態,它將對塊之后的命令起作用。
@echo off
rem "Echo" is off here; commands are not echoed
rem This command does not generate any output
echo This command generate output
echo on
rem "Echo" is on here; commands are echoed
rem This command does not generate any output
echo This command generate output
@rem This command is preceded by "@" so it is not echoed
@echo This command is also not echoed, but produce an output
@echo off
rem "Echo" is off here; commands are not echoed
rem The block below is *parsed* entirely before executed
(
echo This command produces output
echo on
rem Previous command set "Echo" on, but this block was parsed already
rem so the commands placed here are *not* echoed either
echo Command that produce output
)
rem The echo is on here
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.