Is this a bug or a behavior?

Adam Dinwoodie Adam.Dinwoodie@metaswitch.com
Wed Feb 13 16:55:00 GMT 2013


Jack Radigan wrote:
> Using the following script:
> #!/bin/bash
> set -x
> cat << eof | `ls /bin | grep "^grep$"` alpha
> alpha
> omega
> eof

Easier repro showing this phenomena:

    ls /bin | grep '^grep$'

On Linux, you'll get "grep" as output.  Cygwin won't output anything.

> But, the command 'cp /bin/grep ~/.' will copy grep.exe to my home directory.

Yes.  If you ask for a file, the file doesn't exist, but the file with a .exe
extension exists, Cygwin will refer you to the .exe version of the file.  See
<http://cygwin.com/cygwin-ug-net/using-specialnames.html#pathnames-exe>.

> Shouldn't 'ls' be suppressing the '.exe' extension for cygwin binaries
> in the same way that 'cp' appends it?

No: ls tells you about what files actually exist.  "grep.exe" exists; "grep"
doesn't.

> Seems inconsistent not to.

>From that point of view it is; Cygwin is self-consistent, but the very nature
of attempting to write a Linux-like interface on a fundamentally non-Linux like
OS means such issues can't be avoided.  Nobody has yet suggested a more
consistent alternative that still allows, for example, a Linux shell script
that calls unadorned "grep" to work on Cygwin.

If this is causing you a real problem that you can explain, the list may be
able to give you some assistance working around it.  For your (I really hope)
contrived example, replace the command substitution with "/bin/grep" for a
script that will work on both Linux and Cygwin.

-- 
Adam Dinwoodie

Messages posted to this list are made in a personal capacity.



--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple



More information about the Cygwin mailing list