如何让批处理文件中的回显输出一个百分号符号:%

huangapple go评论213阅读模式
英文:

how do i get echo to type out a % in a batch file

问题

我想要下面的代码生效或者有类似的效果。

@echo off
echo 100%
pause


当你打开.bat文件时,它应该显示如下。

100%
按任意键继续. . .


所以我希望`echo`输出百分比符号(%),而不是成为代码的一部分。

我希望它的效果与以下示例相同。

@echo off
echo hi
pause


我只尝试了`echo 100%`,因为我是编程新手,不知道还能尝试什么。
英文:

I want the code below to work or something that does the same thing.

@echo off
echo 100%
pause

When you open the .bat file it shuld look like this.

100%
Press any key to continue . . .

So i want the echo to read out the % and not to be a part of a code.

I want it to work the same as for example

@echo off
echo hi
pause

I have only tried echo 100% because i am a noob at coding so i dont know what else to try.

答案1

得分: 1

百分号在(Windows)批处理文件中具有特殊含义,用于指示变量。例如,echo %username% 将打印 username 变量的内容。

要回显字面上的 % 符号,您需要将其加倍,即 echo 100%%

英文:

The percent sign has special meaning in (Windows) batch files, it is used to indicate a variable. For instance, echo %username% will print the contents of the username variable.

To echo a literal % sign, you need to double it, i.e. echo 100%%

huangapple
  • 本文由 发表于 2023年2月14日 20:57:52
  • 转载请务必保留本文链接:https://go.coder-hub.com/75448174.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定