Okay, I learned that one can use &
or &&
to combine multiple commands into a single line, but it seems that variables that are set
aren't actually available for interpolation in the same line:
C:\Users\Andrew>set foo=hello, world!&& echo %foo%
%foo%
C:\Users\Andrew>echo %foo%
hello, world!
Why can't I make this work, and is there any way to make it work in a single line?
The reason I need a one-liner is that an external program I'm working with accepts a single command as a pre-run hook, and, of course, I need to run multiple commands.
Preemptive Defenses
"
hello, world!
should be surrounded in double-quotes!" Actually, doing so seems to store literal double-quotes in the variable, which I do not want, e.g.C:\Users\Andrew>set bar="hello, world!"&& echo %bar% %bar% C:\Users\Andrew>echo %bar% "hello, world!"
"There should be a space before the
&&
!" Actually, doing so seems to store a trailing space in the variable, which I do not want, e.g.C:\Users\Andrew>set bar="hello, world!"&& echo %bar% %bar% C:\Users\Andrew>echo %bar% "hello, world!"
"Both!" >:(
C:\Users\Andrew>set mu="hello, world!" && echo %mu% %mu% C:\Users\Andrew>echo (%mu%) ("hello, world!" )