PowerShell: Setting an environment variable for a single command only

前端 未结 8 909
闹比i
闹比i 2020-11-29 02:17

On Linux, I can do:

$ FOO=BAR ./myscript

to call \"myscript\" with the environment variable FOO being set.

Is something similar pos

8条回答
  •  猫巷女王i
    2020-11-29 03:19

    Generally, it would be better to pass info to the script via a parameter rather than a global (environment) variable. But if that is what you need to do you can do it this way:

    $env:FOO = 'BAR'; ./myscript
    

    The environment variable $env:FOO can be deleted later like so:

    Remove-Item Env:\FOO
    

提交回复
热议问题