windows - Is It possible to set environment variable and echo it in a single line batch script? -


set a=2 && echo %a% 

this not echo 2 in windows. there way it?

a=2 ; echo $a 

works in bash. want similar behavior on windows

i'm sure there many ways this, here 2 of them:

  • setlocal enabledelayedexpansion&set "foo=bar baz"&echo.!foo!&endlocal
  • set "foo=bar baz"&for /f "tokens=1,* delims==" %%a in ('set foo') if "%%~a"=="foo" echo.%%b

edit: added check "filter" set results 2nd solution, johannes rössel


Comments

Popular posts from this blog

javascript - Enclosure Memory Copies -

php - Replacing tags in braces, even nested tags, with regex -