The Linux kernel project maintains a free copy of the POSIX man pages that you can install on any system.
Your Linux distribution probably has a man-pages-posix
package you can get via your package manager,
but the generic version works anywhere (such as on macOS) almost as easily:
curl -fsSL "https://www.kernel.org/pub/linux/docs/man-pages/man-pages-posix/man-pages-posix-2017-a.tar.xz" |
sudo tar -xJ -C /usr/local/share/man/ -f - --strip-components=1 man-pages-posix-2017/man1p
This extracts just the directory man1p
from the tarball,
which includes only the man pages for the POSIX shell and commands.
(You can also extract the man0p
directory for header files
and man3p
directory for library functions if you like,
but we don’t need those for my primary purpose of shell scripting.)
It adds a section 1p
to the manual containing only the POSIX commands.
You can reference them directly by specifying the section:
# Show the first man page for `sh` found in any section of the manual
man sh
# Show the man page for `sh` from section 1,
# the section for your operating system's general commands
man 1 sh
# Show the man page for `sh` from section 1p,
# the section we just added for POSIX general commands
man 1p sh
Several versions of the man pages are built from the Git repository and published to tarballs.
Update: I wrote a formula to make installation even easier for Homebrew users.
It is in my personal tap
because these docs are licensed restrictively and cannot be included in homebrew-core
.
This formula includes all the sections provided by the man-pages-posix
project:
0p
: Headers1p
: Commands and Built-Ins3p
: Functions
To install it, run:
brew install mrled/cauldron/man-pages-posix
I recommend strict POSIX compliance in shell scripts (furthermore). But how can you know whether a given option or command is pure POSIX or a filthy vendor extension? Most vendor manual pages do not specify, so you have to reference the POSIX documentation directly.
Because of this, I am a regular user of the excellent https://shellhaters.org, which contains links to official POSIX shell and command documentation from The Open Group in HTML.
And now I also can find the docs in my own terminal.