@在cmd中回显 [英] @echo off in cmd

查看:167
本文介绍了@在cmd中回显的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试编写BAT脚本,并且具有以下内容:

I'm trying to write a BAT script and I have the following:

@echo off
REM Comments here
SETLOCAL ENABLEDELAYEDEXPANSION
set PROG_ROOT=C:\Prog
set ONE=1

echo 1>> %PROG_ROOT\test.txt
echo %ONE%>> %PROG_ROOT\test.txt

for /f "tokens=*" %%f in (folders.txt) do (
    echo %%f>> %PROG_ROOT\test.txt
)

ENDLOCAL

我的folder.txt包含数字 5。

My folders.txt contains the number "5".

我的test.txt输出是

My test.txt output is

ECHO is off
ECHO is off
5

我不明白为什么输出的前两行显示 ECHO已关闭,而第三行则正确打印出来。如何打印正确的输出?

I don't understand why the first 2 lines of output has "ECHO is off", while the third line is printed out correctly. How do I print the correct output?

ETA:我尝试​​过

ETA: I tried

echo 1>> %PROG_ROOT\test.txt
echo %ONE% >> %PROG_ROOT\test.txt

我可以打印

ECHO is off
1

但是,我不需要在数字后打印尾随空格。

However, I need to NOT print the trailing space after the number.

推荐答案

1> (更常见的是 n 用于任何数字 n )被解释为重定向,因此 echo 1>> cmd 中显示为 echo 不带参数。没有参数的 echo 将显示当前的 echo 状态(此处, ECHO已关闭)。

1> (and more generally n> for any digit n) is interpreted as a redirection, and thus echo 1>> appears to cmd as an echo with no arguments. echo with no arguments will print the current echo state (here, ECHO is off).

要修复,请使用 ^ 字符对整数进行转义:

To fix, escape the integer with a ^ character:

echo ^1>> %PROG_ROOT\test.txt

这篇关于@在cmd中回显的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆