[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: When would awk issue a warning message about invalid options?
From: |
arnold |
Subject: |
Re: When would awk issue a warning message about invalid options? |
Date: |
Sun, 04 Oct 2020 10:47:48 -0600 |
User-agent: |
Heirloom mailx 12.5 7/5/10 |
Hello.
Arkadiusz Drabczyk <arkadiusz@drabczyk.org> wrote:
> In gawktexi.in it says:
>
> "As long as program text has been supplied, any other options are
> flagged as invalid with a warning message but are otherwise ignored."
>
> And in the manpage it says:
>
> "In compatibility mode, any other options are flagged as invalid, but
> are otherwise ignored. In normal operation, as long as program text
> has been supplied, unknown options are passed on to the AWK program in
> the ARGV array for processing. This is particularly useful for
> running AWK programs via the #! executable interpreter mechanism."
>
> But I'm having a hard trying to understand in what situations would
> awk actually issue a warning message about invalid options.
>
> By some trials and errors I figured out it would if I did this:
>
> $ awk -P -f ./argv --1 --oeue
> awk: unrecognized option '--1'
> awk: unrecognized option '--oeue'
> awk
>
> where ./argv is:
>
> BEGIN { for (i = 0; i < ARGC; i++) print ARGV[i] }
>
> But it's still very unclear:
>
> 1. Does 'program text' in gawktexi.in refer only to -f option?
In this case yes, as you demonstrated:
> I find
> this likely since this sentence immediately follows the list of all
> options and because this doesn't issue any warnings:
>
> $ awk -P 'BEGIN { for (i = 0; i < ARGC; i++) print ARGV[i] }' --1 --oeue
> awk
> --1
> --oeue
This is because an on-the-command-line program automatically ends
the search for options, whereas -f does not, since there may be
additional -f options.
> But in manpage it says:
>
> gawk [ POSIX or GNU style options ] -f program-file [ -- ] file ...
> gawk [ POSIX or GNU style options ] [ -- ] program-text file ...
>
> as if 'program text' was actually referring to what is specified in
> the command line.
That is what it means. The man page and the manual are different
documents and need not be 100% consistent in the use of terminology
between them.
> 2. Shouldn't it be mentioned in gawktexi.in that warning messages are
> only issued in compatibility mode as already mentioned in the manpage?
> It could say for example:
>
> "In compatibility mode, as long as program text has been supplied, any
> other options are flagged as invalid with a warning message but are
> otherwise ignored."
That's probably a good idea.
> 3. What's the difference between -P and -c? This does not issue any
> warnings:
>
> $ awk -c -f ./argv --1 --oeue
> awk
> --1
> --oeue
>
> even though it the manpage it says that -c and -P are doing almost the
> same thing:
>
> -c
> --traditional
> Run in compatibility mode.
>
> -P
> --posix
> This turns on compatibility mode
Read the full text of the paragraph associated with -P:
This turns on compatibility mode, with the following additional
restrictions:
· \x escape sequences are not recognized.
· Only space and tab act as field separators when FS is set to a
single space, newline does not.
· You cannot continue lines after ? and :.
· The synonym func for the keyword function is not recognized.
· The operators ** and **= cannot be used in place of ^ and ^=.
That seems quite clear to me.
Thanks,
Arnold