# Directory Structure

Cygwin knows how to emulate a standard UNIX directory structure, to some extent. This is done through the use of mount tables that map Win32 paths to POSIX ones. The mount table may be set up and modified with the `mount` command. This section explains how to properly organize the structure.

When you set up the system you should decide where you want the root to be mapped. Possible choices are the root of your Windows system, such as `c:` or a directory such as `c:\progra~1\root`.

Execute the following commands inside bash as it is difficult to change the position of the root from the Windows command prompt. Changing the mount points may invalidate `PATH`, if this happens simply exit and relaunch bash. Create the directory if needed, then `umount /` the current root and `mount` it in its new place. You also have to decide if you want to use text or binary mode.

Next, create the traditional main UNIX directories, with the following command (in some shells it is necessary to issue separate `mkdir` commands, each with a single argument).

    /$ mkdir /tmp /bin /etc /var /usr

Next we will initialize the content of these directories.

You should make sure that you always have a valid `/tmp` directory. If you want to avoid creating a real `/tmp`, you can use the `mount` utility to point `/tmp` to another directory, such as `c:\tmp`, or create a symbolic link `/tmp` to point to such a directory.

The `/bin` directory should contain the shell `sh.exe`. You have three choices. The first is to copy this program from the Cygnus `bin` directory. The second is to use `mount` to mount the Cygnus `bin` directory to `/bin` (the advantage of this approach is that your `PATH` will be shorter inside bash). The third is to make `/bin` a symbolic link to the Cygnus `bin` directory.

Note that Cygwin comes with two shells: `bash.exe` and `sh.exe`, which is based on `ash`. The system is faster when `ash` is used as the non-interactive shell. The only functionality supported in `ash` is that of the traditional `sh`. In case of trouble with `ash` make `sh.exe` point to `bash.exe`.

We now turn to `/etc`. You may want to copy in it the `termcap` file from the Cygnus `etc` directory, although the defaults built into the programs suffice for the normal console. You may also use `mount` or create as symbolic link to the Cygnus `etc`, just as for `/bin` above.

Under Windows NT, if you want to create `/etc/passwd` and `/etc/group` (i.e. so that `whoami` works and `ls -l` replaces the UID with a name) just do this:

    /$ cd /etc
    /etc$ mkpasswd -l > /etc/passwd
    /etc$ mkgroup -l > /etc/group

Future changes to your NT registry will NOT be reflected in `/etc/passwd` or `/etc/group` after this so you may want to regenerate these files periodically. Under Windows 9x, you can create and edit these files with a text editor.

The `who` command requires the `/var/run/utmp` to exist. Create it if you wish. The system also logs information in `/var/log/wtmp`, if it exists.

The `/usr` directory is not used by the Cygwin system but it is a standard place to install optional packages.

You may also want to mount directories such as `/a` and `/d` to refer to your local and network drives.

You do not need to create `/dev` in order to set up mounts for devices such as `/dev/null` as these are already automatically simulated inside the Cygwin library.

## Environment Variables

Before starting bash, you must set some environment variables, some of which can also be set or modified inside bash. Cygnus provides you with a .bat file where the most important ones are set before bash in launched. This is the safest way to launch bash initially. The .bat file is installed by default in `\cygnus\cygwin-b20/cygnus.bat` and pointed to in the Start Menu. You can edit it to your liking.

The `CYGWIN` variable is used to configure many global settings for the Cygwin runtime system. Initially you can leave `CYGWIN` unset or set it to `tty` (e.g. to support job control with ^Z etc...) using a syntax like this in the DOS shell, before launching bash.

    C:\Cygnus\> set CYGWIN=tty notitle glob

The `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 (e.g. `C:\WinNT\system32;C:\WinNT`) to UNIX format (e.g., `/WinNT/system32:/WinNT`) when a Cygwin process first starts. Set it so that it contains at least the Cygnus `bin` directory `C:\cygnus\cygwin-b20\H-i586-cygwin32\bin` before launching bash.

The `HOME` environment variable is used by many programs to determine the location of your home directory and we recommend that it be defined. This environment variable is also converted from Windows format when a Cygwin process first starts. Set it to point to your home directory before launching bash.

`make` uses an environment variable `MAKE_MODE` to decide if it uses `command.com` or `/bin/sh` to run command lines. If you are getting strange errors from `make` about "/c not found", set `MAKE_MODE` to `UNIX` at the command prompt or in bash.

    C:\Cygnus\> set MAKE_MODE=UNIX

    /Cygnus$ export MAKE_MODE=UNIX

The `TERM` environment variable specifies your terminal type. You can set it to `cygwin`.

The `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.

## Customizing bash

To set bash up so that cut and paste work properly, click on the "Properties" button of the window, then on the "Misc" tab. Make sure that "Quick Edit" is checked and "Fast Pasting" isn't. These settings will be remembered next time you run bash from that shortcut. Similarly you can set the working directory inside the "Program" tab. The entry "%HOME%" is valid.

Your home directory should contain three initialization files that control the behavior of bash. They are `.profile`, `.bashrc` and `.inputrc`. These initialization files will only be read if `HOME` is defined before starting bash.

`.profile` (other names are also valid, see the bash man page) contains bash commands. It is executed when bash is started as login shell, e.g. from the command `bash --login` (the provided .bat file does not set the switch). This is a useful place to define and export environment variables and bash functions that will be used by bash and the programs invoked by bash. It is a good place to redefine `PATH` if needed. We recommend adding a ":." to the end of `PATH` to also search the current working directory (contrary to DOS, the local directory is not searched by default). Also to avoid delays you should either `unset` `MAILCHECK` or define `MAILPATH` to point to your existing mail inbox.

`.bashrc` is similar to `.profile` but is executed each time an interactive bash shell is launched. It serves to define elements that are not inherited through the environment, such as aliases. If you do not use login shells, you may want to put the contents of `.profile` as discussed above in this file instead.

    shopt -s nocaseglob

will allow bash to glob filenames in a case-insensitive manner. Note that `.bashrc` is not called automatically for login shells. You can source it from `.profile`.

`.inputrc` controls how programs using the readline library (including bash) behave. It is loaded automatically. The full details are in the `readline.info`. Due to a bug in the current readline version, `.inputrc` cannot contain \r, even on text mounted systems. Consider the following settings:

    # Make Bash 8bit clean
    set meta-flag on
    set convert-meta off
    set output-meta on
    # Ignore case while completing
    set completion-ignore-case on

The first three commands allow bash to display 8-bit characters, useful for languages with accented characters. The last line makes filename completion case insensitive, which can be convenient in a Windows environment.