开发者

How can I set a variable in a long one liner using a windows cmdline?

For example:

I want to set a variable and then have it output on the same line.

set /p MESSAGE= && echo %MESSAGE%

But it doe开发者_高级运维sn'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.


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:

setlocal enabledelayedexpansion
set /p MESSAGE= && echo !MESSAGE!

See help set for a discussion of delayed expansion.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜