I want to start the process by setting environment variables like the env command on UNIX, but how can I do this with Windows PowerShell?
I understand that the Set-Item
command can rewrite the environment variables, but this will rewrite the environment of the shell itself, so I have to undo it later, which is a bit troublesome.
Specifically, I would like to start the unit test with a specific environment variable set.For UNIX shells, you can write:
$ env NODE_ENV = test npm test
(This does not necessarily require env.)
PowerShell has a (virtual) drive environment provider that represents environmental variables.
$env:name="BLUE"
You can configure environment variables as shown in .(env:
represents the drive name, $
represents the variable, and name
represents the environment variable name)
The cmdlet can be referenced by $env:name
or env:name
depending on the cmdlet whether or not $
is required.
Same as the environment variable in the batch, it is disabled at the end of the shell (enabled during the boot process)
© 2024 OneMinuteCode. All rights reserved.