Consolidate the handling of which directories need to exist and which
need to be writable. Additionally, add a fatal check for formula
installations to ensure that any directories that need to be writable
are so before attempting an installation.
Fixes#4626.
- Don't allow taking an argument. This doesn't work and never has as it
caches the result regardless of the argument.
- Don't rely on the PATH to check for external commands.
- only document HOMEBREW_* variables in the manpage (although still
read from all the original environment variables).
- resort manpage environment variables in alphabetical order
- check the original path for trailing slashes
Hide these tokens to avoid malicious subprocesses e.g. sending them
over the network. Also, support using these tokens with environment
filtering and clear `HOMEBREW_PATH` from subprocesses to stop them
sniffing it. Finally, use `HOMEBREW_PATH` to detect Homebrew’s user’s
PATH for e.g. `brew doctor` etc.