The `==` operator is not defined by POSIX and many test(1) (also
spelled `[`) implementations do not support it. Replace uses of
`==` with the POSIX-conformant `=` equality operator.
Add double-quotes around all expr(1) left-hand-sides where the
argument is just a variable, to prevent syntax errors when the
variable is empty.
Also avoid the `expr match ...` variant as this is not defined in
POSIX and causes errors in some implementations, including
FreeBSD's.
The `colorize_version` command fails in dash (default /bin/sh on
Ubuntu) with an error like:
local: v0.2.3: bad variable name
Instead of using a local variable, interpolate the function argument
directly to avoid the error.
Some shells do not have a nullglob feature, including dash (default
/bin/sh on Ubuntu) and the Almquist shell (default /bin/sh on
FreeBSD). An mv(1) command in setup_dir is failing due to a glob
not matching anything, so use a more widely supported construction.
In the absense of shasum(1) (which on FreeBSD is provided by Perl,
from ports) nvm falls back to sha1sum(1) which does not exist on
FreeBSD. But FreeBSD does have sha1(1) so look for sha1(1) and use
it if present.
As part of this change, refactor the execution of the checksum
program down into nvm_checksum and also clean up some special-casing
of empty dist checksums, which is already handled by nvm_checksum.
Much of the discussion in the README pertains to zsh as much as
bash, so include a specific reference to ~/.zshrc and remove one
explicit reference to bash.
On FreeBSD, if MANPATH is set it is used verbatim; configuration
files are completely ignored. Therefore, setting MANPATH to (only)
the nvm man dir makes system man pages unreachable.
To get around this, before doing anything else to MANPATH, if it is
empty set it to the output of manpath(1).
One further complication: FreeBSD automatically adds a path to the
man pages path for each path in PATH that ends in "/bin", which
causes "~/.nvm/$VERSION/man" to be added. This interferes with the
subsequent substitution so strip this from MANPATH before the
substitution.