Skip to main content
Added another thing I tried
Source Link
fritzmg
  • 530
  • 7
  • 17

Is it possible to set an actual Windows environment variable from within the Git Bash for example? I know that you can set environment variables via the Git Bash in general with e.g.

FOOBAR=foo; export FOOBAR;

But these environment variables will only be available within the Git Bash environment, not within Windows in general. So if you open the regular Windows Command Prompt afterwards and execute

echo %FOOBAR%

it will not output foo.

The reason for this question: I am starting the SSH Agent with a bash script in ~/.bashrc within Windows. This allows me to then connect to any SSH servers I have access to with my SSH key within the Git Bash. However, any applications that are not run from within Git Bash cannot access the already running SSH Agent, because the SSH_AUTH_SOCK environment variable will not be available outside the Git Bash.

I know the solution in this case would probably be to run the SSH Agent in Windows "natively" (and then I would hope/assume that the SSH Agent is also available on the Git Bash), but I am still curious about whether you can set environment variables from within the Git Bash - that will also be available in the rest of the system.

// edit: I also tried the following on the Git Bash:

cmd //c set FOOBAR=foo

(see here why you need to use a double slash), but still no luck when I open up CMD afterwards:

echo %FOOBAR%
%FOOBAR%

Is it possible to set an actual Windows environment variable from within the Git Bash for example? I know that you can set environment variables via the Git Bash in general with e.g.

FOOBAR=foo; export FOOBAR;

But these environment variables will only be available within the Git Bash environment, not within Windows in general. So if you open the regular Windows Command Prompt afterwards and execute

echo %FOOBAR%

it will not output foo.

The reason for this question: I am starting the SSH Agent with a bash script in ~/.bashrc within Windows. This allows me to then connect to any SSH servers I have access to with my SSH key within the Git Bash. However, any applications that are not run from within Git Bash cannot access the already running SSH Agent, because the SSH_AUTH_SOCK environment variable will not be available outside the Git Bash.

I know the solution in this case would probably be to run the SSH Agent in Windows "natively" (and then I would hope/assume that the SSH Agent is also available on the Git Bash), but I am still curious about whether you can set environment variables from within the Git Bash - that will also be available in the rest of the system.

Is it possible to set an actual Windows environment variable from within the Git Bash for example? I know that you can set environment variables via the Git Bash in general with e.g.

FOOBAR=foo; export FOOBAR;

But these environment variables will only be available within the Git Bash environment, not within Windows in general. So if you open the regular Windows Command Prompt afterwards and execute

echo %FOOBAR%

it will not output foo.

The reason for this question: I am starting the SSH Agent with a bash script in ~/.bashrc within Windows. This allows me to then connect to any SSH servers I have access to with my SSH key within the Git Bash. However, any applications that are not run from within Git Bash cannot access the already running SSH Agent, because the SSH_AUTH_SOCK environment variable will not be available outside the Git Bash.

I know the solution in this case would probably be to run the SSH Agent in Windows "natively" (and then I would hope/assume that the SSH Agent is also available on the Git Bash), but I am still curious about whether you can set environment variables from within the Git Bash - that will also be available in the rest of the system.

// edit: I also tried the following on the Git Bash:

cmd //c set FOOBAR=foo

(see here why you need to use a double slash), but still no luck when I open up CMD afterwards:

echo %FOOBAR%
%FOOBAR%
Source Link
fritzmg
  • 530
  • 7
  • 17

Set a Windows environment variable from within Git Bash

Is it possible to set an actual Windows environment variable from within the Git Bash for example? I know that you can set environment variables via the Git Bash in general with e.g.

FOOBAR=foo; export FOOBAR;

But these environment variables will only be available within the Git Bash environment, not within Windows in general. So if you open the regular Windows Command Prompt afterwards and execute

echo %FOOBAR%

it will not output foo.

The reason for this question: I am starting the SSH Agent with a bash script in ~/.bashrc within Windows. This allows me to then connect to any SSH servers I have access to with my SSH key within the Git Bash. However, any applications that are not run from within Git Bash cannot access the already running SSH Agent, because the SSH_AUTH_SOCK environment variable will not be available outside the Git Bash.

I know the solution in this case would probably be to run the SSH Agent in Windows "natively" (and then I would hope/assume that the SSH Agent is also available on the Git Bash), but I am still curious about whether you can set environment variables from within the Git Bash - that will also be available in the rest of the system.