Arguments That Look Like Options

You may have encountered a situation in which you wanted to specify an argument that started with a hyphen, and your command complained about the improper options that were being used. For example, if grep(1) were used to search a source program for the string --help, you might experience the following under FreeBSD:

$ grep --help tempnam.c
grep: illegal option -- -
usage: grep [-[AB] <num>] [-CEFGLVXHPRSZabchilnqsvwxy]
       [-e <expr>] [-f file] [files ...]
$

The problem with this grep(1) command is that the command was confused about how to treat the text --help. The following technique shows how to avoid this little problem:

$ grep -- --help tempnam.c
$

The example shows that grep(1) understood the -- (double ...

Get Advanced UNIX Programming now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.