bash [ -f filename ] behavior

Harold Hunt
Sun Oct 1 19:58:00 GMT 2000

When building XFree86 from CVS under Cygwin you may encounter a problem
where 'make World' reports that a file 'imake' cannot be moved because it
does not exist.

I have looked into this problem extensively, and it is due to bash behaving
differently under Cygwin than it does under Linux.  However, I believe it
deserves to at least be brought to light.

Make a bash script file containing the following line:
if [ -f imake ]; then mv imake; fi

Follow these steps under Cygwin's Bash:

Run the script in a directory with no files named imake or imake.exe.  The
script will detect that imake does not exist, so it will not attempt to move
the file.

Run 'touch imake', then run the script again.  The script will move file
imake to, as it should.

Run 'touch imake.exe', then run the script again.  The script will think
that a file named 'imake' exists, even though it doesn't; the script will
then attempt to move file 'imake', which does not exist, and the script will

Now, run the same steps under Linux's Bash, and you'll notice that the
script does not get confused when a file named 'imake.exe' exists.

This bug, or feature (as it may help compatibility), currently causes
XFree86 to fail when building under Cygwin.  I'm going to send in a patch to
XFree86 to check for 'imake.exe' before checking for 'imake'; that will fix
the build bustage for now.  But, I figure the Cygwin guys might want to
evaluate whether this is really desired behavior...

(I'm not on the Cygwin list, just the Cygwin/XFree86 list, so Cygwin people
please CC me.  Thanks.)


More information about the Cygwin-xfree mailing list