In linux I would go:
setenv -p MYVAR "somevalue"
But this doesn't seem to work in cygwin.
To change directory, you can use cd command with the target directory parameter. The target directory can be expressed in a DOS-like manner (d:/ or d:/Ogo1. 2). Note that drives in Cygwin are treated as directories, and the usage of forward slash in place of the DOS backslash (d:/Ogo1.
In a new installation of Cygwin, your home directory will be in C:/cygwin/home/<user>/ , and can be accessed by the usual ~ shortcut.
Description. The cygpath program is a utility that converts Windows native filenames to Cygwin POSIX-style pathnames and vice versa. It can be used when a Cygwin program needs to pass a file name to a native Windows program, or expects to get a file name from a native Windows program.
The best way to set up environment variables in cygwin is to create a bash profile and execute that profile everytime you login and run the shell.
In my .bash_profile file , this is the setting I have
JAVA_HOME = C:/Program Files/Java/jdk1.7.0_51 export JAVA_HOME export PATH=$PATH:$JAVA_HOME/bin
Once you run bash, check out echo $JAVA_HOME and you should see the path as output.
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:
export MYVAR="somevalue"
The export
part lets the shell know that it is an environment variable instead of a local variable.
If you type ls -a
in your home directory, you should see some or all of the following files:
.bashrc .bash_profile .profile
.bash_profile
is executed for login shells, and .bashrc
is executed for interactive non-login shells. To most simply ensure that your environment variable is always set, open up .bash_profile
and add the text:
export MYVAR="somevalue"
Your shell with then execute .bash_profile
every time it starts up, and it will run this command. You will then have the MYVAR
variable accessible all of the time. If you didn't export
the variable, it would only be accessible within your .bash_profile
file.
You can check that this variable is defined by printing its value to your shell:
echo $MYVAR
You can delete (unset) the variable with:
unset $MYVAR
As an aside, regarding .bashrc
vs .bash_profile
vs. .profile
, see these answers:
.bash_profile
and .bashrc
.profile
and .bash_profile
For simplicity of configuration, I recommend sourcing your .bashrc
file from .bash_profile
. Add this to .bash_profile
:
if [ -f ${HOME}/.bashrc ]; then source ${HOME}/.bashrc fi
This will load .bashrc
from .bash_profile
.
If you do this, you can instead put the following line in .bashrc
, if you wish:
export MYVAR="somevalue"
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