All Windows environment variables are imported when Cygwin starts. Apart from that, you may wish to specify settings of several important environment variables that affect Cygwin's operation.
CYGWIN variable is used to configure a few global
settings for the Cygwin runtime system. Typically you can leave
CYGWIN unset, but if you want to set one ore more
options, you can set it using a syntax like this, depending on the shell
in which you're setting it. Here is an example in CMD syntax:
set CYGWIN=error_start:C:\cygwin\bin\gdb.exe glob
This is, of course, just an example. For the recognized settings of the
CYGWIN environment variable, see
the section called “The
Locale support is controlled by the
LC_xxx environment variables. For a more detailed description
see the section called “Internationalization”.
PATH environment variable is used by Cygwin
applications as a list of directories to search for executable files
to run. This environment variable is converted from Windows format
C:\Windows\system32;C:\Windows) to UNIX format
when a Cygwin process first starts.
Set it so that it contains at least the
directory where "
x:\cygwin is the "root" of your
cygwin installation if you wish to use cygwin tools outside of bash.
This is usually done by the batch file you're starting your shell with.
HOME environment variable is used by many programs to
determine the location of your home directory. This environment variable,
if it exists, is converted from Windows format when a Cygwin process first
starts. However, it's usually set in the shell profile scripts in the /etc
directory, and it's not recommended to set
the variable in your Windows environment.
TERM environment variable specifies your terminal
type. It is automatically set to
cygwin if you have
not set it to something else.
LD_LIBRARY_PATH environment variable is used by
the Cygwin function
dlopen () as a list of
directories to search for .dll files to load. This environment variable
is converted from Windows format to UNIX format when a Cygwin process
first starts. Most Cygwin applications do not make use of the
dlopen () call and do not need this variable.
GMON_OUT_PREFIX environment variable is helpful
in some situations when profiling Cygwin programs. For more information,
see the section called “Profiling programs that fork”. Only software developers with a
need to profile their programs have a use for this variable.
In addition to
there are three other environment
variables which, if they exist in the Windows environment, are
converted to UNIX format:
TEMP. The first is not set by default in the
Windows environment but the other two are, and they point to the
default Windows temporary directory. If set, these variables will be
used by some Cygwin applications, possibly with unexpected results.
You may therefore want to unset them by adding the following two lines
unset TMP unset TEMP
This is done in the default
Alternatively, you could set
TEMP to point to
/tmp or to
any other temporary directory of your choice. For example:
export TMP=/tmp export TEMP=/tmp
There is a restriction when calling Win32 API functions which require a fully set up application environment. Cygwin maintains its own environment in POSIX style. The Win32 environment is usually stripped to a bare minimum and not at all kept in sync with the Cygwin POSIX environment.
If you need the full Win32 environment set up in a Cygwin process, you have to call
#include <sys/cygwin.h> cygwin_internal (CW_SYNC_WINENV);
to synchronize the Win32 environment with the Cygwin environment.
Note that this only synchronizes the Win32 environment once with the
Cygwin environment. Later changes using the
putenv calls are not reflected in the Win32
environment. In these cases, you have to call the aforementioned
cygwin_internal call again.