开发者

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

开发者 https://www.devze.com 2023-01-26 00:13 出处:网络
For example: I want to set a variable and then have it output on the same line. set /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 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

精彩评论

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

关注公众号