public inbox for cygwin@cygwin.com
 help / color / mirror / Atom feed
* Incorrect expansion of a program argument that is a special character?
@ 2021-07-21 11:42 Ev Drikos
  2021-07-21 12:18 ` Russell VT
  2021-07-21 15:44 ` Brian Inglis
  0 siblings, 2 replies; 4+ messages in thread
From: Ev Drikos @ 2021-07-21 11:42 UTC (permalink / raw)
  To: cygwin

Hello,

When I run the program below from my home directory in a PowerShell
Console (Windows 8-1) I've to use an extra backslash character as
shown below or the star is expanded. Which happens only when the
program has been compiled in Cygwin.

Is this a bug or a known feature?

Ev. Drikos

----------------------------------------------
PS C:\Users\suser> .\args.exe '\*'

*
argc=1
PS C:\Users\suser>
----------------------------------------------

#include <stdio.h>
int main(int argc, char *argv[]){
int i;
for (i=1; i < argc; i++) {
  printf("\n%s",argv[i]);
}//for
 printf("\nargc=%d\n",argc-1);
return 0;
}

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

* Re: Incorrect expansion of a program argument that is a special character?
  2021-07-21 11:42 Incorrect expansion of a program argument that is a special character? Ev Drikos
@ 2021-07-21 12:18 ` Russell VT
       [not found]   ` <CAK5_-8oOKuSQd35f2KF=q7Xy5mMQkukEUJa_dja+1WtHUGMcRQ@mail.gmail.com>
  2021-07-21 15:44 ` Brian Inglis
  1 sibling, 1 reply; 4+ messages in thread
From: Russell VT @ 2021-07-21 12:18 UTC (permalink / raw)
  To: Ev Drikos; +Cc: cygwin

Note that Powershell and BASH wildcard (globbing) may be notably different,
which includes how items may be "escaped" to prevent such globbing
operations.

Moreover, in a UN*X shell, it is generally thought that it's the user's
responsibility to declare how how file expansion should work, generally
defaulting to the "one or more" presence (where true regular expressions
use an asterisk as "zero or more"). In this way, shells and general regular
expressions may differ.

TLDR; In any environment, "arguments" are different between the command
line, and the program itself.

Basically, you need to understand how any given shell will pass arguments
to your program, and that exercise is generally outside of general
executable-type discussion (ie. it is almost a "religious war" as to how
various shells may process arguments, regular expressions, or wildcards ...
along with what options a user may specify to change the behaviour)

Do you have an example of where the program functions as-expected, along
with examples as to how the identical binary functions differently in
other environments?

Hope that lights a few lightbulbs for ya!

Russell VT


On Wed, Jul 21, 2021 at 4:44 AM Ev Drikos via Cygwin <cygwin@cygwin.com>
wrote:

> Hello,
>
> When I run the program below from my home directory in a PowerShell
> Console (Windows 8-1) I've to use an extra backslash character as
> shown below or the star is expanded. Which happens only when the
> program has been compiled in Cygwin.
>
> Is this a bug or a known feature?
>
> Ev. Drikos
>
> ----------------------------------------------
> PS C:\Users\suser> .\args.exe '\*'
>
> *
> argc=1
> PS C:\Users\suser>
> ----------------------------------------------
>
> #include <stdio.h>
> int main(int argc, char *argv[]){
> int i;
> for (i=1; i < argc; i++) {
>   printf("\n%s",argv[i]);
> }//for
>  printf("\nargc=%d\n",argc-1);
> return 0;
> }
>
> --
> Problem reports:      https://cygwin.com/problems.html
> FAQ:                  https://cygwin.com/faq/
> Documentation:        https://cygwin.com/docs.html
> Unsubscribe info:     https://cygwin.com/ml/#unsubscribe-simple
>


-- 
Russell M. Van Tassell <russellvt@gmail.com>

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

* Fwd: Incorrect expansion of a program argument that is a special character?
       [not found]   ` <CAK5_-8oOKuSQd35f2KF=q7Xy5mMQkukEUJa_dja+1WtHUGMcRQ@mail.gmail.com>
@ 2021-07-21 14:21     ` Ev Drikos
  0 siblings, 0 replies; 4+ messages in thread
From: Ev Drikos @ 2021-07-21 14:21 UTC (permalink / raw)
  To: cygwin

---------- Forwarded message ----------
From: Ev Drikos <drikosev@gmail.com>
Date: Wed, 21 Jul 2021 17:17:50 +0300
Subject: Re: Incorrect expansion of a program argument that is a
special character?
To: Russell VT <russellvt@gmail.com>

On 7/21/21, Russell VT <russellvt@gmail.com> wrote:
> ...
> Do you have an example of where the program functions as-expected, along
> with examples as to how the identical binary functions differently in
> other environments?
> ...

Hello,

In example, the program runs as expected if any of the following situations:
1. I run it in another directory (ie C:\Users\suser\tmp)
2. I run it in a classic Windows terminal (but no Greek characters)
3. I've compiled the program with cl (MS VC++)

It's the third test I made (compile with MS VC++) that made me wonder
if I face some Cygwin bug. Clearly, it's a question, not a bug report.

Thank you,
Ev. Drikos

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

* Re: Incorrect expansion of a program argument that is a special character?
  2021-07-21 11:42 Incorrect expansion of a program argument that is a special character? Ev Drikos
  2021-07-21 12:18 ` Russell VT
@ 2021-07-21 15:44 ` Brian Inglis
  1 sibling, 0 replies; 4+ messages in thread
From: Brian Inglis @ 2021-07-21 15:44 UTC (permalink / raw)
  To: cygwin; +Cc: Ev Drikos

On 2021-07-21 05:42, Ev Drikos via Cygwin wrote:
> When I run the program below from my home directory in a PowerShell
> Console (Windows 8-1) I've to use an extra backslash character as
> shown below or the star is expanded. Which happens only when the
> program has been compiled in Cygwin.
> 
> Is this a bug or a known feature?

It's a feature which emulates the argument expansions normally performed 
by shells under Unix like systems.
If a Cygwin program is not run from a Cygwin shell, then the Cygwin 
program startup argument parsing obeys the quoting rules and performs 
the argument expansions which running from a Cygwin shell would normally 
perform, so the program sees the same arguments as running from a Cygwin 
shell would generate.

Run "info bash 'pattern matching'" then press u (Up) and repeat to see 
other argument expansions and processing performed; tab and press Enter 
to view Topics; press q to Quit.

-- 
Take care. Thanks, Brian Inglis, Calgary, Alberta, Canada

This email may be disturbing to some readers as it contains
too much technical detail. Reader discretion is advised.
[Data in binary units and prefixes, physical quantities in SI.]

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

end of thread, other threads:[~2021-07-21 15:44 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-07-21 11:42 Incorrect expansion of a program argument that is a special character? Ev Drikos
2021-07-21 12:18 ` Russell VT
     [not found]   ` <CAK5_-8oOKuSQd35f2KF=q7Xy5mMQkukEUJa_dja+1WtHUGMcRQ@mail.gmail.com>
2021-07-21 14:21     ` Fwd: " Ev Drikos
2021-07-21 15:44 ` Brian Inglis

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