Home > database >  Is there a command to refresh environment variables from the Bash Terminal (Git bash) in Windows?
Is there a command to refresh environment variables from the Bash Terminal (Git bash) in Windows?

Time:02-19

The problem

I use Git Bash which is based on MinGW. Around the day I often change the Windows PATH environment variable, in it are the paths to my tools, such as PHP, for example.

I use tools to change PHP versions, this tool automatically changes the PHP environment variable to a different version.

I would like to have a command that from the bash terminal itself I can run it and refresh the environment variables.

What have I tried?

I have tried almost everything in this question without any success. The only thing that has worked for me is to run a new terminal with administrator privileges, but I would not want to have this as the best option.

I tried:

I guess none of the above worked for me because they were not made for git bash, that's why I created this question. I have also tried all of the above with a terminal like Cygwin which is similar to Git Bash, without success.

I've come close to achieving this with this command, but I can't get it to work.

export PATH="$(cygpath -pu "`{ reg query 'HKEY_CURRENT_USER\Environment' /v PATH | grep PATH | cut -c23- ; reg query 'HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Environment' /v PATH | grep PATH | cut -c30-; } | tr "\n" " "`")"

Basically what I am trying to achieve with the above command is to take the PATH environment variables out of the registry and put them in export PATH to update bash. But first I have to concatenate the system variables and the user variables. See this for more info.

CodePudding user response:

I used a custom script created by Badr Elmers Works just as I expected and works in Git Bash, Cygwin.

More info here

  • Related