Linux - Cygwin

1 - What Is Cygwin ?

Cygwin is a Linux-like environment under Windows.

Cygwin consists of:

  • A DLL (cygwin1.dll) which acts as a Linux API emulation layer providing substantial Linux API functionality.
  • A collection of tools which provide Linux look and feel.
  • A bash console to interact

Standard Windows command line tools can even be intermixed within the UNIX/Linux shell script environment to administer the Windows system.

3 - Management

3.1 - Installation

  • Download and run the setup.exe file.
  • Choose the package

I’d personally suggest scrolling up in the list and installing the Devel packages as well, as this will allow you to compile and run many UNIX programs on your Windows computer. If you would like to use emacs, xemacs, or vi/vim locally on your Windows computer, install the Editors packages. Additional packages can be installed later by re-running Setup.exe.

  • Finish

3.2 - Directory Structure

The installation directory (by default, c:\cygwin) is the root of the Unix-like file system, which contains bin, etc, home, tmp, and usr directories as would be found on a GNU/Linux or other Unix system.

After the Shell launch, the current (working) directory is /home/user, where user is your Windows login name.

Automatic mount points Description Example
/usr/bin the installation directory C:/cygwin64/bin
/usr/lib the /lib directory. C:/cygwin64/lib

This choice is safe and usually shouldn't be changed. An fstab entry for them is not required.

3.3 - How to begin / start the shell

To open a Cygwin terminal window:

  • click on the Cygwin desktop icon,
  • choose the Cygwin entry from your start menu,

Within this window, the GNU bash shell is running, with POSIX syntax (directory separators are '/', not '\').

The shell Cygwin.bat is located in the root installation directory of Cygwin.

@echo off
 
C:
chdir C:\cygwin64\bin
 
bash --login -i

Initially, the current (working) directory is /home/user, where user is your Windows login name.

4 - Snippet

4.1 - Path conversion

# CYGINW == 1 if Cygwin is detected, else 0.
if [[ $(uname -a) =~ "CYGWIN" ]]; then
  CYGWIN=1
else
  CYGWIN=0
fi
 
# If Cygwin is detected, a DIR variable must be converted to Windows format.
(( CYGWIN )) && ADIR=$(cygpath --path --mixed "${ADIR}")

5 - Support

5.1 - My Windows logon name has a space in it

Don't use this directory if your Windows login name contains a space; make another and use that one instead, e.g., by typing these commands at the bash prompt:

mkdir /home/bob
echo "export HOME=/home/bob" >>.bashrc
echo "export HOME=/home/bob" >>.bash_profile
cp .bashrc .bash_profile /home/bob
echo "cd" >>.bashrc

Close your Cygwin terminal window and open another one; your current directory should now be /home/bob (or whatever you chose to call it). See the Cygwin FAQ (look for “My Windows logon name has a space in it”) for other solutions to this common problem.

6 - Documentation / Reference

os/linux/cygwin.txt · Last modified: 2018/11/10 14:20 by gerardnico