This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 2 years ago.
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
接受
或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
发布评论
评论(1)
只是一些提示:
@
表示“不要将命令回显到控制台”。命令回显由echo on
和echo off
控制。Echo
默认情况下ON,因此命令@echo off
表示“关闭echo
,但不< code>echo 将此行发送到控制台。因此,一旦执行
@echo off
,就无需在命令之前添加@
。第三个
echo
语句,您已指定targAtname,未定义,因此报告没有显示该项目的!,而是
%
。意味着“变量在运行时的值,而不是在解析时的值”,并且实际上仅适用于调用更改变量的循环的语句,例如for
循环,但是正如aschipfl
所指出的,它很有用克服echo
语句中的特殊字符影响让我们检查一下批处理对于一次分配的作用:
批处理替换第一个stpath 部分。 > %~p1 的参数,因此实际执行的命令是
将
A
分配给targetpath
,然后尝试执行B\< /code> 因此出现错误消息。
在字符串赋值上,使用语法
引号可以防止命令行上出现杂散尾随空格,并且还可以解决大多数特殊字符问题。
顺便说一句:
将
echo
名称以target
开头的所有变量Just a few tips:
@
means "do notecho
the command to the console". Command-echoing is controlled byecho on
andecho off
.Echo
is ON by default, so the command@echo off
means "Turnecho
off, but do notecho
this line to the console.`Hence, once an
@echo off
is executed, there is no need to put@
before commands.In your third
echo
statement, you have specified targAtname, which is undefined, hence the report shows nothing for that item.!
in place of%
means "the value of the variable as it is at run-time, not at parse-time" and is really only applicable where a statement invokes a loop which changes the variable, like afor
loop, but asaschipfl
has pointed out, it comes in useful to overcome the special-characters effects in anecho
statement.Let's examine what batch does for one assignment:
Batch substitutes the
path
part of the 1st parameter for%~p1
so the actual command executed ishence it assigns
A
totargetpath
and then attempts to executeB\
hence the error message.On a string assignment, it is standard practice on SO to use the syntax
The quotes protect against stray trailing spaces on the command line, and will also cure most problems with special characters.
BTW:
will
echo
all variables whose names starttarget