Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set an environment variable in git bash

Tags:

git

git-bash

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?

like image 981
bier hier Avatar asked Dec 09 '15 02:12

bier hier


People also ask

How do I set environment variables in Git bash?

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.

How do I set an environment variable?

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.

How do I set an environment variable in github?

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.

What are environment variables in bash?

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.


2 Answers

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 
like image 141
chepner Avatar answered Sep 21 '22 17:09

chepner


If you want to set environment variables permanently in Git-Bash, you have two options:

  1. Set a regular Windows environment variable. Git-bash gets all existing Windows environment variables at startup.

  2. 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.

like image 37
Alexandr Avatar answered Sep 22 '22 17:09

Alexandr