In Bash, I can do EDITOR=vim command
and command
will be run with EDITOR
set to vim
, but this won't affect the value of EDITOR
in the shell itself. Is it possible to do this in cmd.exe
?
Windows – Setting and using variable within same command line in Windows cmd.exe
command lineshellwindows
Best Answer
Note that
cmd /C "set "EDITOR=vim" && echo %EDITOR%"
would not work.Nor would
cmd /C "setlocal ENABLEDELAYEDEXPANSION && set "EDITOR=vim" && echo !EDITOR!"
What would is the
/V
option, to enable delayed environment variable expansion using!
as delimiter.As noted below by maoizm, it is
cmd /V /C
, notcmd /C /V
(which would not work)Typically, you need this when you have to replace a value used multiple times in a long command line.
For instance, to deploy a file to Nexus (in multiple lines for readability):
Instead of having to replace group, artifact (used 2 times) and version in a long and complex command line, you can edit them at the beginning of said command. It is clearer/easier to manipulate and change the parameter values.