Reputation: 496
I want to execute a path in the Windows Powershell terminal based on the concatenation of an environment variable and a string, in one line.
For instance, cmd.exe
allows me to execute the following:
c:\temp> %PYTHON2PATH%\python.exe main.py
With Powershell, it seems that one needs to refer to the environment variable using:
PS c:\temp> $Env:PYTHON2PATH\python.exe
Although this only works if I press TAB (which then de-references the variable), before pressing Enter. Is there is way do this without having to de-reference it using the TAB key?
Upvotes: 1
Views: 108
Reputation: 200523
Use the call operator (&
) if you want to invoke command strings with unexpanded variables:
& $env:PYTHON2PATH\python.exe
or
& "${env:PYTHON2PATH}\python.exe"
Upvotes: 2