Options begin with a dash, and consist of a single character. GNU style long options consist of two dashes and a keyword. The keyword can be abbreviated, as long the abbreviation allows the option to be uniquely identified. If the option takes an argument, then the keyword is either immediately followed by an equals sign (`=') and the argument's value, or the keyword and the argument's value are separated by whitespace. For brevity, the discussion below only refers to the traditional short options; however the long and short options are interchangeable in all contexts.
Each long option for
gawk has a corresponding
POSIX-style option. The options and their meanings are as follows:
FSvariable to fs (see section Specifying How Fields are Separated).
awkprogram is to be found in source-file instead of in the first non-option argument.
BEGINrule (see section Other Command Line Arguments). The `-v' option can only set one variable, but you can use it more than once, setting another variable each time, like this: `awk -v foo=1 -v bar=2 ...'.
awk. They are provided for compatibility, but otherwise ignored by
gawkhas no predefined limits.
gawk-specific options are available:
awklanguage are disabled, so that
gawkbehaves just like the Bell Labs research version of Unix
awk. `--traditional' is the preferred form of this option. See section Extensions in
gawkNot in POSIX
awk, which summarizes the extensions. Also see section Downward Compatibility and Debugging.
gawkaccepts, and then exit.
awkimplementations. Some warnings are issued when
gawkfirst reads your program. Others are issued at run-time, as your program executes.
awk(see section Major Changes between V7 and SVR3.1).
gawkextensions (just like `--traditional'), and adds the following additional restrictions:
\xescape sequences are not recognized (see section Escape Sequences).
FSis equal to a single space.
funcfor the keyword
functionis not recognized (see section Function Definition Syntax).
FSto be a single tab character (see section Specifying How Fields are Separated).
fflushbuilt-in function is not supported (see section Built-in Functions for Input/Output).
gawkwill also issue a warning if both options are supplied.
gawkdoes not provide them by default. This prevents old
awkprograms from breaking.
-W source program-text
gawk. This allows you to determine if your copy of
gawkis up to date with respect to whatever the Free Software Foundation is currently distributing. It is also useful for bug reports (see section Reporting Problems and Bugs).
Any other options are flagged as invalid with a warning message, but are otherwise ignored.
In compatibility mode, as a special case, if the value of fs supplied
to the `-F' option is `t', then
FS is set to the tab
"\t"). This is only true for `--traditional', and not
(see section Specifying How Fields are Separated).
The `-f' option may be used more than once on the command line.
If it is,
awk reads its program source from all of the named files, as
if they had been concatenated together into one big file. This is
useful for creating libraries of
awk functions. Useful functions
can be written once, and then retrieved from a standard place, instead
of having to be included into each individual program.
You can type in a program at the terminal and still use library functions,
by specifying `-f /dev/tty'.
awk will read a file from the terminal
to use as part of the
awk program. After typing your program,
type Control-d (the end-of-file character) to terminate it.
(You may also use `-f -' to read program source from the standard
input, but then you will not be able to also use the standard input as a
source of data.)
Because it is clumsy using the standard
awk mechanisms to mix source
file and command line
gawk provides the
`--source' option. This does not require you to pre-empt the standard
input for your source code, and allows you to easily mix command line
and library source code
(see section The
AWKPATH Environment Variable).
If no `-f' or `--source' option is specified, then
will use the first non-option command line argument as the text of the
program source code.
If the environment variable
gawk will behave in strict POSIX mode, exactly as if
you had supplied the `--posix' command line option.
Many GNU programs look for this environment variable to turn on
strict POSIX mode. If you supply `--lint' on the command line,
gawk turns on POSIX mode because of
then it will print a warning message indicating that POSIX
mode is in effect.
You would typically set this variable in your shell's startup file. For a Bourne compatible shell (such as Bash), you would add these lines to the `.profile' file in your home directory.
POSIXLY_CORRECT=true export POSIXLY_CORRECT
csh compatible shell,(17)
you would add this line to the `.login' file in your home directory.
setenv POSIXLY_CORRECT true
Go to the first, previous, next, last section, table of contents.