public inbox for cygwin@cygwin.com
 help / color / mirror / Atom feed
* Is this a bug or a behavior?
@ 2013-02-13 16:14 Jack Radigan
  2013-02-13 16:55 ` Adam Dinwoodie
  0 siblings, 1 reply; 7+ messages in thread
From: Jack Radigan @ 2013-02-13 16:14 UTC (permalink / raw)
  To: cygwin

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

Output from bash on Linux:
+ cat
++ ls /bin
++ grep '^grep$'
+ grep alpha
alpha

Output from bash on Cygwin:
+ cat
++ ls /bin
++ grep '^grep$'
+ alpha
./ls-test: line 3: alpha: command not found

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

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

Seems inconsistent not to.

--
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

^ permalink raw reply	[flat|nested] 7+ messages in thread

* RE: Is this a bug or a behavior?
  2013-02-13 16:14 Is this a bug or a behavior? Jack Radigan
@ 2013-02-13 16:55 ` Adam Dinwoodie
  2013-02-13 17:44   ` Christopher Faylor
  2013-02-15  5:29   ` Centrych Administrator
  0 siblings, 2 replies; 7+ messages in thread
From: Adam Dinwoodie @ 2013-02-13 16:55 UTC (permalink / raw)
  To: cygwin

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

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Is this a bug or a behavior?
  2013-02-13 16:55 ` Adam Dinwoodie
@ 2013-02-13 17:44   ` Christopher Faylor
  2013-02-15  5:29   ` Centrych Administrator
  1 sibling, 0 replies; 7+ messages in thread
From: Christopher Faylor @ 2013-02-13 17:44 UTC (permalink / raw)
  To: cygwin

On Wed, Feb 13, 2013 at 04:55:01PM +0000, Adam Dinwoodie wrote:
>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.

Yep, but if you want to write code that will work on both *nix and
Cygwin you could do this:

ls /bin | sed -n -e 's/\.exe$//' -e '/grep/p'

That works on both Cygwin and Linux.

cgf

--
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

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Is this a bug or a behavior?
  2013-02-13 16:55 ` Adam Dinwoodie
  2013-02-13 17:44   ` Christopher Faylor
@ 2013-02-15  5:29   ` Centrych Administrator
  2013-02-15 16:47     ` Larry Hall (Cygwin)
  1 sibling, 1 reply; 7+ messages in thread
From: Centrych Administrator @ 2013-02-15  5:29 UTC (permalink / raw)
  To: cygwin

On 02/13/2013 11:55 AM, Adam Dinwoodie wrote:
> 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>. 

Thanks, already aware of that, and it's why I raised this question.

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

I'm not clear on what your standard for "self-consistent" is, or why 
filenames are an interface issue.

Those aside, consider these two lines:

     $ rm -rf * && mkdir a && touch grep && cp grep /bin/grep a
     $ rm -rf * && mkdir a && touch grep && cp /bin/grep grep a

The first line executes as expected while the second, which reverses the 
order of files, fails after copying the .exe with the following:

     cp: cannot create regular file `a/grep': File exists

Now, take these two sets:

     $ rm -rf * && touch foo grep && cp /bin/grep.exe .
     $ mv foo grep && ls -i

     $ rm -rf * && touch foo && cp /bin/grep.exe .
     $ mv -n foo grep

The first set works as expected while the second deletes grep.exe during 
the rename even though no-clobber is explicitly passed to mv.

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

How can it ever be consistent while 'filename' and filename.exe' are 
allowed to exist in the same directory?

Is there some way to differentiate between a Windows .exe and a Cygwin 
binary, like grep.exe, that's intended to execute within the Cygwin 
environment?

> For your (I really hope) contrived example... 

Unfortunately, it wasn't contrived.  It was an actual question in a BASH 
scripting module that I unnecessarily have to slog through.



--
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

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Is this a bug or a behavior?
  2013-02-15  5:29   ` Centrych Administrator
@ 2013-02-15 16:47     ` Larry Hall (Cygwin)
  2013-02-18 16:40       ` Centrych Administrator
  0 siblings, 1 reply; 7+ messages in thread
From: Larry Hall (Cygwin) @ 2013-02-15 16:47 UTC (permalink / raw)
  To: cygwin

On 2/15/2013 12:29 AM, Centrych Administrator wrote:

<snip>

> How can it ever be consistent while 'filename' and filename.exe' are allowed
> to exist in the same directory?
>
> Is there some way to differentiate between a Windows .exe and a Cygwin
> binary, like grep.exe, that's intended to execute within the Cygwin
> environment?

I believe these questions are the crux of your inquiry so I've stripped
out the surrounding details.  Apologies if you feel I've removed something
you feel is a significant point.

This goes to the heart of a difference between how Windows and Linux treat
executables and various ingrained assumptions both make about their
respective expectations (essentially what Adam said ;-) ).  Cygwin does try
to bridge this gap but it has its limits as well.  This is actually not
new issue and has been discussed many times in the past on this list.  If
you're interested in the details or, even better, in improving what's
currently implemented, I'd recommend reviewing previous discussions, the
ideas they generated, and the issues and limitations mentioned.  That
should help you understand the current state and provide you with an
informed basis if you want to take a swing at providing some patch.

The only short answer I can give you is that the current state is a 
compromise.  That doesn't mean there isn't a better one.  Just that it's
a complicated area for many reasons so getting to a better state is also
complicated.

-- 
Larry

_____________________________________________________________________

A: Yes.
 > Q: Are you sure?
 >> A: Because it reverses the logical flow of conversation.
 >>> Q: Why is top posting annoying in email?

--
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

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Is this a bug or a behavior?
  2013-02-15 16:47     ` Larry Hall (Cygwin)
@ 2013-02-18 16:40       ` Centrych Administrator
  0 siblings, 0 replies; 7+ messages in thread
From: Centrych Administrator @ 2013-02-18 16:40 UTC (permalink / raw)
  To: cygwin

On 02/15/2013 11:46 AM, Larry Hall (Cygwin) wrote:
> I believe these questions are the crux of your inquiry so I've stripped
> out the surrounding details.  Apologies if you feel I've removed 
> something
> you feel is a significant point.
>
> This goes to the heart of a difference between how Windows and Linux 
> treat
> executables and various ingrained assumptions both make about their
> respective expectations (essentially what Adam said ;-) ).  Cygwin 
> does try
> to bridge this gap but it has its limits as well.  This is actually not
> new issue and has been discussed many times in the past on this list.  If
> you're interested in the details or, even better, in improving what's
> currently implemented, I'd recommend reviewing previous discussions, the
> ideas they generated, and the issues and limitations mentioned. That
> should help you understand the current state and provide you with an
> informed basis if you want to take a swing at providing some patch.
>
> The only short answer I can give you is that the current state is a 
> compromise.  That doesn't mean there isn't a better one.  Just that 
> it's a complicated area for many reasons so getting to a better state 
> is also complicated.

Fair enough.  I'd like to take a crack at it once I clear some other 
things off of my plate first.  Will have to look through previous 
conversations before I know if it's something I can competently tackle.

Thanks.

-jack-


--
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

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Is this a bug or a behavior?
@ 2013-02-15 22:06 Ian Pellew
  0 siblings, 0 replies; 7+ messages in thread
From: Ian Pellew @ 2013-02-15 22:06 UTC (permalink / raw)
  To: cygwin

Doesn't $PATH come into this?
Cygwin.dll may well have some inbuilt commands too?
Being a heavey Cygwin user who does not venture too deep !

Ian_Uk
.


--
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

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2013-02-18 16:40 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-02-13 16:14 Is this a bug or a behavior? Jack Radigan
2013-02-13 16:55 ` Adam Dinwoodie
2013-02-13 17:44   ` Christopher Faylor
2013-02-15  5:29   ` Centrych Administrator
2013-02-15 16:47     ` Larry Hall (Cygwin)
2013-02-18 16:40       ` Centrych Administrator
2013-02-15 22:06 Ian Pellew

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).