如何使用 Windows 命令行在长一行中设置变量?
例如:
我想设置一个变量,然后将其输出在同一行。
设置 /p MESSAGE= && echo %MESSAGE%
但它并不像您期望的那样工作。有没有办法通过管道来回显,或者有没有更好的方法来分隔单独的命令?
谢谢。
For example:
I want to set a variable and then have it output on the same line.
set /p MESSAGE= && echo %MESSAGE%
But it doesn't quite work like you expect. Is there a way to pipe it to echo or is there a better way to delimit separate commands?
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这无法按照您在此处尝试的方式工作,因为环境变量是在解析一行时扩展的,而不是在执行时扩展的。由于
%MESSAGE%
仅在执行第一部分之后才有意义,因此这是行不通的。然而,这将:
请参阅
help set
以获取延迟扩展的讨论。This cannot work the way you try here since environment variables are expanded while parsing a line, not when executing it. Since
%MESSAGE%
is only meaningful after executing the first part, this cannot work.This however will:
See
help set
for a discussion of delayed expansion.