When I punch from the windows gitbash command line:
set $HOME = c
and do :
echo $HOME
It does not set it to c
? How can I change/set the value of an environment variable?
To declare a new environment variable for Git, we need to follow along with the commands in the shell. So, open a Bash shell command-line (terminal). Using this easy syntax, create and specify a new environment variable that is available to your running command-line shell and any applications started from it.
On the Windows taskbar, right-click the Windows icon and select System. In the Settings window, under Related Settings, click Advanced system settings. On the Advanced tab, click Environment Variables. Click New to create a new environment variable.
To set a custom environment variable, you must define it in the workflow file. The scope of a custom environment variable is limited to the element in which it is defined. You can define environment variables that are scoped for: The entire workflow, by using env at the top level of the workflow file.
Environment variables are special variables (like $HOME ) that contain information about your login session. They're stored for the system shell to use when executing commands. They exist whether you're using Linux, Mac, or Windows. Many of these variables are set by default during installation or user creation.
A normal variable is set by simply assigning it a value; note that no whitespace is allowed around the =
:
HOME=c
An environment variable is a regular variable that has been marked for export to the environment.
export HOME HOME=c
You can combine the assignment with the export
statement.
export HOME=c
If you want to set environment variables permanently in Git-Bash, you have two options:
Set a regular Windows environment variable. Git-bash gets all existing Windows environment variables at startup.
Set up env variables in .bash_profile
file.
.bash_profile
is by default located in a user home folder, like C:\users\userName\git-home\.bash_profile
. You can change the path to the bash home folder by setting HOME
Windows environment variable.
.bash_profile
file uses the regular Bash syntax and commands
# Export a variable in .bash_profile export DIR=c:\dir # Nix path style works too export DIR=/c/dir # And don't forget to add quotes if a variable contains whitespaces export ANOTHER_DIR="c:\some dir"
Read more information about Bash configurations files.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With