f



How to read /? literally from ARGV[1]

If the user types the program name followed by "/?", I want
to output a help usage message so the command line call is:

e.g. gawk -f specialtasktest.awk /?

However, I can't catch /? from ARGV[1].
# specialtasktest.awk
BEGIN {
  print ARGV[1]
}

gawk -f specialtasktest.awk /?
=> /d

It seems due to filename expansion on the command line
arguments /? gets changed to /d (not shure what /d is).

How to get /? instead of /d as ARGV[1]?

I'm on Windows, behavior is the same for GAWK and TAWK.
0
Marc
11/19/2016 6:32:34 PM
comp.lang.awk 3450 articles. 0 followers. Post Follow

12 Replies
209 Views

Similar Articles

[PageSpeed] 12

On 19.11.2016 19:32, Marc de Bourget wrote:
> If the user types the program name followed by "/?", I want
> to output a help usage message so the command line call is:
> 
> e.g. gawk -f specialtasktest.awk /?
> 
> However, I can't catch /? from ARGV[1].
> # specialtasktest.awk
> BEGIN {
>   print ARGV[1]
> }
> 
> gawk -f specialtasktest.awk /?
> => /d
> 
> It seems due to filename expansion on the command line
> arguments /? gets changed to /d (not shure what /d is).
> 
> How to get /? instead of /d as ARGV[1]?
> 
> I'm on Windows, behavior is the same for GAWK and TAWK.

What shell are you using on Windows? It might help to escape
or quote the globbing patterns, "/?", '/?', or /\?, but that
depends on the shell. It might be work to use Unix convention
and define -? as option switch for the help usage message, or
any syntax that is not using path delimiting characters like
the slashes / or \.

Janis

0
Janis
11/19/2016 6:47:24 PM
Le samedi 19 novembre 2016 19:47:25 UTC+1, Janis Papanagnou a =C3=A9crit=C2=
=A0:
> On 19.11.2016 19:32, Marc de Bourget wrote:
> > If the user types the program name followed by "/?", I want
> > to output a help usage message so the command line call is:
> >=20
> > e.g. gawk -f specialtasktest.awk /?
> >=20
> > However, I can't catch /? from ARGV[1].
> > # specialtasktest.awk
> > BEGIN {
> >   print ARGV[1]
> > }
> >=20
> > gawk -f specialtasktest.awk /?
> > =3D> /d
> >=20
> > It seems due to filename expansion on the command line
> > arguments /? gets changed to /d (not shure what /d is).
> >=20
> > How to get /? instead of /d as ARGV[1]?
> >=20
> > I'm on Windows, behavior is the same for GAWK and TAWK.
>=20
> What shell are you using on Windows? It might help to escape
> or quote the globbing patterns, "/?", '/?', or /\?, but that
> depends on the shell. It might be work to use Unix convention
> and define -? as option switch for the help usage message, or
> any syntax that is not using path delimiting characters like
> the slashes / or \.
>=20
> Janis

I use the default Windows command line (cmd.exe).
Only '/?' and /\? would work. They print the content literally.
However, this is much too ugly, I don't want to force the user
to write something like /\? to get help. /? is quite usual for
Windows command line tools so I would like not to renounce it.
What is your output for /? on Linux? Thank you.
0
Marc
11/19/2016 7:10:12 PM
On 19.11.2016 20:10, Marc de Bourget wrote:
> Le samedi 19 novembre 2016 19:47:25 UTC+1, Janis Papanagnou a écrit :
>> On 19.11.2016 19:32, Marc de Bourget wrote:
>>> If the user types the program name followed by "/?", I want
>>> to output a help usage message so the command line call is:
>>>
>>> e.g. gawk -f specialtasktest.awk /?
>>>
>>> However, I can't catch /? from ARGV[1].
>>> # specialtasktest.awk
>>> BEGIN {
>>>   print ARGV[1]
>>> }
>>>
>>> gawk -f specialtasktest.awk /?
>>> => /d
>>>
>>> It seems due to filename expansion on the command line
>>> arguments /? gets changed to /d (not shure what /d is).
>>>
>>> How to get /? instead of /d as ARGV[1]?
>>>
>>> I'm on Windows, behavior is the same for GAWK and TAWK.
>>
>> What shell are you using on Windows? It might help to escape
>> or quote the globbing patterns, "/?", '/?', or /\?, but that
>> depends on the shell. It might be work to use Unix convention
>> and define -? as option switch for the help usage message, or
>> any syntax that is not using path delimiting characters like
>> the slashes / or \.
>>
>> Janis
> 
> I use the default Windows command line (cmd.exe).
> Only '/?' and /\? would work. They print the content literally.
> However, this is much too ugly, I don't want to force the user
> to write something like /\? to get help. /? is quite usual for
> Windows command line tools so I would like not to renounce it.
> What is your output for /? on Linux? Thank you.

On Linux (or Unix systems in general) the ? is [usually] taken
as globbing character, it tries to find a matching file. If no
file match is found it is passed literally:

  $ awk 'BEGIN { print ARGV[1] }' /?
  /?

(In Unix shell you can also disable file globbing, so that even
in presence of a file named, say d, below / (root) you will get
always a literal /? .)

Janis

0
Janis
11/19/2016 7:30:38 PM
In article <d694b725-6602-4d54-8f5a-da21ad08ceca@googlegroups.com>,
Marc de Bourget  <marcdebourget@gmail.com> wrote:
>Le samedi 19 novembre 2016 19:47:25 UTC+1, Janis Papanagnou a écrit :
>> On 19.11.2016 19:32, Marc de Bourget wrote:
>> > If the user types the program name followed by "/?", I want
>> > to output a help usage message so the command line call is:
>> > 
>> > e.g. gawk -f specialtasktest.awk /?
>> > 
>> > However, I can't catch /? from ARGV[1].
>> > # specialtasktest.awk
>> > BEGIN {
>> >   print ARGV[1]
>> > }
>> > 
>> > gawk -f specialtasktest.awk /?
>> > => /d
>> > 
>> > It seems due to filename expansion on the command line
>> > arguments /? gets changed to /d (not shure what /d is).
>> > 
>> > How to get /? instead of /d as ARGV[1]?
>> > 
>> > I'm on Windows, behavior is the same for GAWK and TAWK.
>> 
>> What shell are you using on Windows? It might help to escape
>> or quote the globbing patterns, "/?", '/?', or /\?, but that
>> depends on the shell. It might be work to use Unix convention
>> and define -? as option switch for the help usage message, or
>> any syntax that is not using path delimiting characters like
>> the slashes / or \.
>> 
>> Janis
>
>I use the default Windows command line (cmd.exe).
>Only '/?' and /\? would work. They print the content literally.
>However, this is much too ugly, I don't want to force the user
>to write something like /\? to get help. /? is quite usual for
>Windows command line tools so I would like not to renounce it.
>What is your output for /? on Linux? Thank you.

My first reaction seeing your post was: Are you using Cygwin?
(Janis will understand...)

But I think Janis has actually missed a subtlety.  Even if you are not using
a Unix-like shell, the real problem is that, under Windows, both GAWK and
TAWK do their own filename expansion (to make up for the fact that the
defective shells shipped with Windows don't).  The result is that you get
filename expansion even if you don't want it.

Anyway, I just tested with TAWK (Note that I don't have a GAWK for Windows
at the moment).  With this as "x.awk":
    BEGIN { print ARGV[1] }

I can reproduce the problem, like this:

C> echo foo > \q
C> awkw -f x /?
/q
C> del \q

Note that I have to have a file in the root directory with a single
character name in order to make it happen.  Note also that / and \ are
interchangeable here.

I'm curious what single character file you had in your root directory...
(Apparently, something named 'd'...)

P.S.  I think the best overall solution is to have your 'help' option be
'/h' instead of '/?'.  Yes, I know other programs can get away with '/?',
but that's not really relevant.  They don't have the GAWK or TAWK runtimes
to contend with.  Finally, do note that the '/' character isn't an issue.
Only the '?' is causing a problem.  You don't need to switch to '-' as
Janis suggested.

-- 
"There are two things that are important in politics.
The first is money and I can't remember what the second one is."
	- Mark Hanna -
0
gazelle
11/19/2016 7:45:53 PM
Le samedi 19 novembre 2016 20:45:54 UTC+1, Kenny McCormack a =C3=A9crit=C2=
=A0:
> In article <d694b725-6602-4d54-8f5a-da21ad08ceca@googlegroups.com>,
> Marc de Bourget  <marcdebourget@gmail.com> wrote:
> >Le samedi 19 novembre 2016 19:47:25 UTC+1, Janis Papanagnou a =C3=A9crit=
=C2=A0:
> >> On 19.11.2016 19:32, Marc de Bourget wrote:
> >> > If the user types the program name followed by "/?", I want
> >> > to output a help usage message so the command line call is:
> >> >=20
> >> > e.g. gawk -f specialtasktest.awk /?
> >> >=20
> >> > However, I can't catch /? from ARGV[1].
> >> > # specialtasktest.awk
> >> > BEGIN {
> >> >   print ARGV[1]
> >> > }
> >> >=20
> >> > gawk -f specialtasktest.awk /?
> >> > =3D> /d
> >> >=20
> >> > It seems due to filename expansion on the command line
> >> > arguments /? gets changed to /d (not shure what /d is).
> >> >=20
> >> > How to get /? instead of /d as ARGV[1]?
> >> >=20
> >> > I'm on Windows, behavior is the same for GAWK and TAWK.
> >>=20
> >> What shell are you using on Windows? It might help to escape
> >> or quote the globbing patterns, "/?", '/?', or /\?, but that
> >> depends on the shell. It might be work to use Unix convention
> >> and define -? as option switch for the help usage message, or
> >> any syntax that is not using path delimiting characters like
> >> the slashes / or \.
> >>=20
> >> Janis
> >
> >I use the default Windows command line (cmd.exe).
> >Only '/?' and /\? would work. They print the content literally.
> >However, this is much too ugly, I don't want to force the user
> >to write something like /\? to get help. /? is quite usual for
> >Windows command line tools so I would like not to renounce it.
> >What is your output for /? on Linux? Thank you.
>=20
> My first reaction seeing your post was: Are you using Cygwin?
> (Janis will understand...)
>=20
> But I think Janis has actually missed a subtlety.  Even if you are not us=
ing
> a Unix-like shell, the real problem is that, under Windows, both GAWK and
> TAWK do their own filename expansion (to make up for the fact that the
> defective shells shipped with Windows don't).  The result is that you get
> filename expansion even if you don't want it.
>=20
> Anyway, I just tested with TAWK (Note that I don't have a GAWK for Window=
s
> at the moment).  With this as "x.awk":
>     BEGIN { print ARGV[1] }
>=20
> I can reproduce the problem, like this:
>=20
> C> echo foo > \q
> C> awkw -f x /?
> /q
> C> del \q
>=20
> Note that I have to have a file in the root directory with a single
> character name in order to make it happen.  Note also that / and \ are
> interchangeable here.
>=20
> I'm curious what single character file you had in your root directory...
> (Apparently, something named 'd'...)
>=20
> P.S.  I think the best overall solution is to have your 'help' option be
> '/h' instead of '/?'.  Yes, I know other programs can get away with '/?',
> but that's not really relevant.  They don't have the GAWK or TAWK runtime=
s
> to contend with.  Finally, do note that the '/' character isn't an issue.
> Only the '?' is causing a problem.  You don't need to switch to '-' as
> Janis suggested.
>=20
> --=20
> "There are two things that are important in politics.
> The first is money and I can't remember what the second one is."
> 	- Mark Hanna -

Yes, exactly, I have a directory named c:\d
If I change it to c:\e the result is /e instead of /d :-)

In the meantime I have noticed at least for exe file compilation
there is a solution with the TAWK compiler option "-ee":
TAWK manual, page 97:
"-ee (This option is two letters). Disables filename expansion of
filenames in the ARGV array of the compiled program. The filename
patterns are left in the ARGV array, allowing you to do your own
filename expansion, if you so desire. Note that a compiled TAWK
program still processes filname patterns in each element of the
ARGV array when it comes to read and process that filename, so
this option does not actually disable the use of filename patterns
in the compiled program, it just makes the original filename patterns
show up in the ARGV array. As usual, if your program changes any
element of the ARGV array before TAWK processes that element as a
filename, TAWK processes the changed ARGV element rather than the
original."

There is also an "-eo" option which seems useful: Manual, page 98:
"-eo (This option is two letters). Suppresses default command line
processing of options by the compiled TAWK program. Specifically,
the compiled TAWK program will ignore any -F, -v, -w or =E2=80=94 options
in its command line. The -eo and -ee options can be combined, for
example: -eoe"

So, at least for TAWK there aren't any problems if I compile
specialtasktest.awk to a native Windows exe file:
# specialtasktest.awk=20
BEGIN {=20
=C2=A0 print ARGV[1]=20
}=20

>awkcw -xe -ee specialtasktest.awk
or
>awkcw -xe -eo -ee specialtasktest.awk
=3D> specialtasktest.exe

>specialtasktest.exe /?
=3D> /?
0
Marc
11/19/2016 8:17:48 PM
On 19.11.2016 20:45, Kenny McCormack wrote:
> In article <d694b725-6602-4d54-8f5a-da21ad08ceca@googlegroups.com>,
> Marc de Bourget  <marcdebourget@gmail.com> wrote:
>> Le samedi 19 novembre 2016 19:47:25 UTC+1, Janis Papanagnou a écrit� :
>>>
>>> What shell are you using on Windows? It might help to escape
> 
> But I think Janis has actually missed a subtlety.  Even if you are not using
> a Unix-like shell, the real problem is that, under Windows, both GAWK and
> TAWK do their own filename expansion (to make up for the fact that the
> defective shells shipped with Windows don't).  The result is that you get
> filename expansion even if you don't want it.

I am aware of that; that's why I asked what shell the OP uses as my very
first question. Of course escapes or quotes won't help in those "DOS shells",
but they do help if using environments with other non-MS shells that have
been developed for Windows (you named one of them).

> Only the '?' is causing a problem.  You don't need to switch to '-' as
> Janis suggested.

You don't need to switch it to '-' but it's an option to do so, isn't it?
Since with '/?' the file expansion will generally pop in if - as in the OP's
case - there's a file /d beneath the root directory - not an uncommon case,
I'd say. And would '-?' be expanded on Windows if there's no file match? (I
have no Windows running at the moment, but I'd be surprised.) I'd expect
that /? would match any single letter file under the current root directory,
while -? would only match in the rare case that you have a two-letter file
starting with a '-' in your current working directory. (Or am I mistaken?
Please CMIIW.)

Janis

0
Janis
11/19/2016 8:49:48 PM
El 19/11/2016 19:32, Marc de Bourget escribi�:
> If the user types the program name followed by "/?", I want
> to output a help usage message so the command line call is:
>
> e.g. gawk -f specialtasktest.awk /?
>
> However, I can't catch /? from ARGV[1].
> # specialtasktest.awk
> BEGIN {
>    print ARGV[1]
> }
>
> gawk -f specialtasktest.awk /?
> => /d
>
> It seems due to filename expansion on the command line
> arguments /? gets changed to /d (not shure what /d is).
>
> How to get /? instead of /d as ARGV[1]?
>
> I'm on Windows, behavior is the same for GAWK and TAWK.
>

You can try mawk. It seems to not expand /? nor /*.

Regards.
-- 
Manuel Collado - http://lml.ls.fi.upm.es/~mcollado

0
Manuel
11/20/2016 1:01:01 AM
Le samedi 19 novembre 2016 21:49:50 UTC+1, Janis Papanagnou a =C3=A9crit=C2=
=A0:
> On 19.11.2016 20:45, Kenny McCormack wrote:
> > In article <d694b725-6602-4d54-8f5a-da21ad08ceca@googlegroups.com>,
> > Marc de Bourget  <marcdebourget@gmail.com> wrote:
> >> Le samedi 19 novembre 2016 19:47:25 UTC+1, Janis Papanagnou a =C3=83=
=C2=A9crit=C3=82 :
> >>>
> >>> What shell are you using on Windows? It might help to escape
> >=20
> > But I think Janis has actually missed a subtlety.  Even if you are not =
using
> > a Unix-like shell, the real problem is that, under Windows, both GAWK a=
nd
> > TAWK do their own filename expansion (to make up for the fact that the
> > defective shells shipped with Windows don't).  The result is that you g=
et
> > filename expansion even if you don't want it.
>=20
> I am aware of that; that's why I asked what shell the OP uses as my very
> first question. Of course escapes or quotes won't help in those "DOS shel=
ls",
> but they do help if using environments with other non-MS shells that have
> been developed for Windows (you named one of them).
>=20
> > Only the '?' is causing a problem.  You don't need to switch to '-' as
> > Janis suggested.
>=20
> You don't need to switch it to '-' but it's an option to do so, isn't it?
> Since with '/?' the file expansion will generally pop in if - as in the O=
P's
> case - there's a file /d beneath the root directory - not an uncommon cas=
e,
> I'd say. And would '-?' be expanded on Windows if there's no file match? =
(I
> have no Windows running at the moment, but I'd be surprised.) I'd expect
> that /? would match any single letter file under the current root directo=
ry,
> while -? would only match in the rare case that you have a two-letter fil=
e
> starting with a '-' in your current working directory. (Or am I mistaken?
> Please CMIIW.)
>=20
> Janis

With gawk -f specialtasktest.awk -? I have encountered 4 strange cases:
1. A directory named: "-" (of course without double quotes):
=3D> Output always: -
2. A directory named "--": Output: Nothing
3. A directory named "-e" (with existence of directory "--"):
=3D> Output: -e
4. A directory named "-e" (without existence of directory "--"):
>gawk -f specialtasktest.awk -?
=3D> output:
gawk: option requires an argument -- e
Usage: gawk [POSIX or GNU style options] ...
....

This is funny, isn't it?
0
Marc
11/20/2016 11:22:09 AM
On 11/19/2016 12:32 PM, Marc de Bourget wrote:
> If the user types the program name followed by "/?", I want
> to output a help usage message so the command line call is:
>
> e.g. gawk -f specialtasktest.awk /?
>
> However, I can't catch /? from ARGV[1].
> # specialtasktest.awk
> BEGIN {
>   print ARGV[1]
> }
>
> gawk -f specialtasktest.awk /?
> => /d
>
> It seems due to filename expansion on the command line
> arguments /? gets changed to /d (not shure what /d is).
>
> How to get /? instead of /d as ARGV[1]?
>
> I'm on Windows, behavior is the same for GAWK and TAWK.
>

It's your OS that's doing that, not awk, so this question is OT here and you're 
more likely to get a good answer in a Windows NG.

     Ed.
0
Ed
11/20/2016 2:49:44 PM
Le dimanche 20 novembre 2016 20:30:30 UTC+1, Manuel Collado a =C3=A9crit=C2=
=A0:
> El 19/11/2016 19:32, Marc de Bourget escribi=C3=B3:
> > If the user types the program name followed by "/?", I want
> > to output a help usage message so the command line call is:
> >
> > e.g. gawk -f specialtasktest.awk /?
> >
> > However, I can't catch /? from ARGV[1].
> > # specialtasktest.awk
> > BEGIN {
> >    print ARGV[1]
> > }
> >
> > gawk -f specialtasktest.awk /?
> > =3D> /d
> >
> > It seems due to filename expansion on the command line
> > arguments /? gets changed to /d (not shure what /d is).
> >
> > How to get /? instead of /d as ARGV[1]?
> >
> > I'm on Windows, behavior is the same for GAWK and TAWK.
> >
>=20
> You can try mawk. It seems to not expand /? nor /*.
>=20
> Regards.
> --=20
> Manuel Collado - http://lml.ls.fi.upm.es/~mcollado

Yes I know. I use MAWK whenever I can but most times its
features are simply too Spartan so I use most often TAWK.
The TAWK compiler option mentioned above solves the issue.
0
Marc
11/20/2016 8:07:53 PM
In article <f67599d1-0c8a-4b6b-830d-1dcf3494cb3a@googlegroups.com>,
Marc de Bourget  <marcdebourget@gmail.com> wrote:
....
>Yes I know. I use MAWK whenever I can but most times its
>features are simply too Spartan so I use most often TAWK.
>The TAWK compiler option mentioned above solves the issue.

I think this is the right way to go.  As I've said many times, there's no
good reason to run GAWK under Windows if one can use TAWK.  I don't
understand why you are even worrying about GAWK.  Note that I *could*
understand someone asking this question and wanting a sensible answer *if*
that person did not have TAWK.  But we know that you do, so...

(P.S.)
This comment also applies to your next question about fseek/ftell on GAWK.
Incidentally, the answer to that question is "Not likely.  I don't see how
that would be considered in the remit of the GAWK developers."

-- 
Modern Conservative: Someone who can take time out from demanding more
flag burning laws, more abortion  laws, more drug laws, more obscenity
laws, and more police authority  to make warrantless arrests to remind
us that we need to "get the government off our backs".
0
gazelle
11/20/2016 8:43:14 PM
In article <o0sd57$9l6$1@dont-email.me>,
Ed Morton  <mortonspam@gmail.com> wrote:
....
>it's your OS that's doing that, not awk, so this question is OT here and
>you're more likely to get a good answer in a Windows NG.

Not true.

In fact, this question has nothing to do with Windows (per se) or the
Windows shell.  As I indicated in earlier posts, the user's shell is
irrelevant.

Rather, the problem has to do with functionalities of (one or two,
depedning on how you look at it) specific implementation(s) of GAWK for the
Windows platform.  But the issue is with those implementations, not with
anything in Windows per se.

In comp.lang.c, they consider implementations off-topic.  But we're not
like that here.

-- 
If it seems like I'm not responding to some moronic criticism that you've
posted in response to one of my posts, be aware that I do not debate with idiots.

It doesn't mean you've won anything...
0
gazelle
11/20/2016 8:50:34 PM
Reply: