set A=2 && echo %A%
This does not echo A as 2 in windows. Is there any way to do it?
A=2 ; echo $A
works in bash. I want a similar behavior on windows
set A=2 && echo %A%
This does not echo A as 2 in windows. Is there any way to do it?
A=2 ; echo $A
works in bash. I want a similar behavior on windows
Use one & instead of 2.
The following command in a bat file:
set A=2 & echo %A%
prints nicely 2 as output
I'm sure there are many ways to do this, here are two of them:
setlocal ENABLEDELAYEDEXPANSION&set "foo=bar baz"&echo.!foo!&endlocal
set "foo=bar baz"&for /F "tokens=1,* delims==" %%A in ('set foo') do if "%%~A"=="foo" echo.%%B
Edit: Added check to "filter" set results for 2nd solution, thanks Johannes Rössel
Note the !
surrounding A
instead of %
.
@ECHO OFF
SETLOCAL ENABLEDELAYEDEXPANSION
SET A=2 & ECHO !A!
ENDLOCAL