In linux I would go:
setenv -p MYVAR "somevalue"
But this doesn’t seem to work in cygwin.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
By default Cygwin is running the Bourne shell or Bash, so the command to set a variable is different. This is the code you need:
The
exportpart lets the shell know that it is an environment variable instead of a local variable.If you type
ls -ain your home directory, you should see some or all of the following files:.bash_profileis executed for login shells, and.bashrcis executed for interactive non-login shells. To most simply ensure that your environment variable is always set, open up.bash_profileand add the text:Your shell with then execute
.bash_profileevery time it starts up, and it will run this command. You will then have theMYVARvariable accessible all of the time. If you didn’texportthe variable, it would only be accessible within your.bash_profilefile.You can check that this variable is defined by printing its value to your shell:
You can delete (unset) the variable with:
Brief words on shell config files
As an aside, regarding
.bashrcvs.bash_profilevs..profile, see these answers:.bash_profileand.bashrc.profileand.bash_profileFor simplicity of configuration, I recommend sourcing your
.bashrcfile from.bash_profile. Add this to.bash_profile:This will load
.bashrcfrom.bash_profile.If you do this, you can instead put the following line in
.bashrc, if you wish: