PowerShell: Setting an environment variable for a single command only

前端 未结 8 889
闹比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条回答
  •  离开以前
    2020-11-29 03:18

    2 easy ways to do it in a single line:

    $env:FOO='BAR'; .\myscript; $env:FOO=''
    $env:FOO='BAR'; .\myscript; Remove-Item Env:\FOO
    

    Just summarized information from other answers (thank you folks) which don't contain pure one-liners for some reason.

提交回复
热议问题