Looking at the man page for grep
I noticed there are two different paths to the command. Does this mean I have multiple grep
tools on my system? Are the synopsis lines that have the same path just different usage examples of the same tool? I am using OS X 10.10.5
NAME
grep - search a file for a pattern
SYNOPSIS
/usr/bin/grep [-bchilnsvw] limited-regular-expression
[filename]...
/usr/xpg4/bin/grep [-E | -F] [-c | -l | -q] [-bhinsvx] -e pattern_list...
[-f pattern_file]... [file]...
/usr/xpg4/bin/grep [-E | -F] [-c | -l | -q] [-bhinsvx]
[-e pattern_list]... -f pattern_file... [file]...
/usr/xpg4/bin/grep [-E | -F] [-c | -l | -q] [-bhinsvx] pattern
[file]...
DESCRIPTION
The grep utility searches text files for a pattern and
prints all lines that contain that pattern. It uses a com-
pact non-deterministic algorithm.
A follow up question: Where do man pages come from? Are they generated dynamically or are they part of a static installation?
Best Answer
You say you're on a macOS machine, but the manual looks suspiciously like the
grep
manual on a Solaris machine. Here is the manual forgrep
on OSX 10.9 for comparison.On Solaris, there are several utilities with multiple implementations, and
grep
is one of them. The ones in/usr/bin
adhere to XPG3, which is short for "X/Open Portability Guide, Issue 3". The Single Unix Specification is based on XPG4 (ref: Wikipedia X/Open article)The XPG3
grep
in/usr/bin
does, for example, not support extended regular expressions, while the XPG4grep
in/usr/xpg4/bin
does.If a utility has several synopsis lines in its manual, then these are usually describing mutually exclusive ways to invoke the tool.
These:
.. show that you may use either
-e
or-f
(or both) but that you must use one of them.The last one,
... shows that if you use neither
-e
nor-f
, then thepattern
needs to be specified on the command line.See also
standards(5)
on Solaris.Manuals are installed "statically", i.e. as separate files that the
man
command reads and displays. However, depending on your system, some of them may begroff
ormandoc
source files, while others may be pre-formatted as text files, sometimes stored in a sibling directory to the unformatted manuals, often called something likecat
. They may sometimes also be compressed. Read theman
manual on your system (man man
) to see how manuals are handled there.Most often, manuals may be found in
/usr/share/man
,/usr/local/share/man
, or some such location.