Special filenames

DOS devices

Windows filenames invalid under Windows are also invalid under Cygwin. This means that base filenames such as AUX, COM1, LPT1 or PRN (to name a few) cannot be used in a regular Cygwin Windows or POSIX path, even with an extension (prn.txt). However the special names can be used as filename extensions (file.aux). You can use the special names as you would under DOS, for example you can print on your default printer with the command cat filename > PRN (make sure to end with a Form Feed).

POSIX devices

There is no need to create a POSIX /dev directory as it is simulated within Cygwin automatically. It supports the following devices: /dev/null, /dev/tty and /dev/comX (the serial ports). These devices cannot be seen with the command ls /dev although commands such as ls /dev/tty work fine.

The .exe extension

Executable program filenames end with .exe but the .exe need not be included in the command, so that traditional UNIX names can be used. To the contrary the extensions ".bat" and ".com" cannot be omitted.

As a side effect, the ls filename gives information about filename.exe if filename.exe exists and filename does not. In the same situation the function call stat("filename",..) gives information about filename.exe. The two files can be distinguished by examining their inodes, as demonstrated below.

C:\Cygnus\> ls * 
a      a.exe     b.exe
C:\Cygnus\> ls -i a a.exe
445885548 a       435996602 a.exe
C:\Cygnus\> ls -i b b.exe
432961010 b       432961010 b.exe

The gcc compiler produces an executable named filename.exe when asked to produce filename. This allows many makefiles written for UNIX systems to work well under Cygwin.

Unfortunately the install and strip commands do distinguish between filename and filename.exe. They fail when working on a non-existing filename even if filename.exe exists, thus breaking some makefiles. This problem can be solved by writing install and strip shell scripts to provide the extension ".exe" when needed.

The @pathnames

To circumvent the limitations on shell line length in the native Windows command shells, Cygwin programs expand their arguments starting with "@" in a special way. If a file pathname exists, the argument @pathname expands recursively to the content of pathname. Double quotes can be used inside the file to delimit strings containing blank space. In the following example compare the behaviors of the bash built-in echo and of the program /bin/echo.

Example 3-4. Using @pathname

/Cygnus$ echo  'This     is "a     long" line' > mylist
/Cygnus$ echo @mylist
@mylist
/Cygnus$ /bin/echo @mylist
This is a     long line
/Cygnus$ rm mylist
/Cygnus$ /bin/echo @mylist
@mylist