Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Reading environmental variables in PowerShell or cmd yield different results

I have been puzzling over an issue with environmental variables in Windows 7.

We have a Jenkins server which cannot find the SSH keys in the %HOME% environmental variable as it wants to access the path:

/c/users/jenkins

However if I use

echo %HOME%

in a normal command prompt window as my Jenkins user then the result is

C:\users\jenkins

However, if I use the environment command in Windows PowerShell I also get

/c/user/jenkins

In the normal GUI accessible from the system properties - advanced tag -> environmental I get the following

C:\users\jenkins

I have tried setting them back, but the issue persists. In so far as Jenkins gets the same output as PowerShell.

How do I set them back? (Not that cmd and the Windows system think that they are set wrong.) How on earth does accessing the same environmental variable give me different outputs? Is there a way in which this can occur? Where are they stored so I can manually edit where they are stored?

like image 515
JamesD Avatar asked Oct 27 '25 03:10

JamesD


1 Answers

As mentioned in a comment by @Luis, the env command is not part of PowerShell. It is likely provided by some other set of utilities that you have installed and is intended to emulate the Linux env command.

To refer to an environment variable in PowerShell, use the $env:<variable-name> syntax or the environment provider - Get-Content env:\<variable-name>.

To set an environment variable, you can use $env:<variable-name> = "<variable-value>"

For more information, try running help about_Environment_Variables in PowerShell.

like image 195
Ben Randall Avatar answered Oct 28 '25 19:10

Ben Randall



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!