nvm-sh / nvm

Node Version Manager - POSIX-compliant bash script to manage multiple active node.js versions

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

`nvm.sh` is messing up (the output of) `env`

ppo opened this issue · comments

nvm.sh is messing up with the output of env… and I guess not just the output.

I've this configured:

export NVM_DIR="$HOME/.nvm"
NVM_HOMEBREW=$( brew --prefix nvm )
[ -s "${NVM_HOMEBREW}/nvm.sh" ] && source "${NVM_HOMEBREW}/nvm.sh"

When I execute env to display my environment variables, I see this:
(when I don't load nvm.sh, the output is normal)

(------- 23 empty lines -------)

            \\#${SEARCH_PATTERN}# !d;
            \\#^[^v]# d;
            \\#^versions\$# d;
            print $1, $10
            print $1, $10, "*"
            s#${NVM_VERSION_DIR_IOJS}/#versions/${NVM_IOJS_PREFIX}/#;
            s#^${NVM_DIR}/##;
            s#^v#${NVM_NODE_PREFIX}/v#;
            s#^versions/##;
          " -e 's#^\([^/]\{1,\}\)/\(.*\)$#\2.\1#;' | command sort -t. -u -k 1.2,1n -k 2,2n -k 3,3n | command sed -e 's#\(.*\)\.\([^\.]\{1,\}\)$#\2-\1#;' -e "s#^${NVM_NODE_PREFIX}-##;")";

(------- many things in between -------)

BASH_FUNC_nvm%%=() {  if [ "$#" -lt 1 ]; then
BASH_FUNC_nvm_add_iojs_prefix%%=() {  nvm_echo "$(nvm_iojs_prefix)-$(nvm_ensure_version_prefix "$(nvm_strip_iojs_prefix "${1-}")")"
BASH_FUNC_nvm_alias%%=() {  local ALIAS;
BASH_FUNC_nvm_alias_path%%=() {  nvm_echo "$(nvm_version_dir old)/alias"
BASH_FUNC_nvm_auto%%=() {  local NVM_MODE;
BASH_FUNC_nvm_binary_available%%=() {  nvm_version_greater_than_or_equal_to "$(nvm_strip_iojs_prefix "${1-}")" v0.8.6
BASH_FUNC_nvm_cache_dir%%=() {  nvm_echo "${NVM_DIR}/.cache"
BASH_FUNC_nvm_cd%%=() {  \cd "$@"
BASH_FUNC_nvm_change_path%%=() {  if [ -z "${1-}" ]; then
BASH_FUNC_nvm_check_file_permissions%%=() {  nvm_is_zsh && setopt local_options nonomatch;
BASH_FUNC_nvm_clang_version%%=() {  clang --version | command awk '{ if ($2 == "version") print $3; else if ($3 == "version") print $4 }' | command sed 's/-.*$//g'

(------- many things in between -------)

BASH_FUNC_nvm_use_if_needed%%=() {  if [ "_${1-}" = "_$(nvm_ls_current)" ]; then
BASH_FUNC_nvm_validate_implicit_alias%%=() {  local NVM_IOJS_PREFIX;
BASH_FUNC_nvm_version%%=() {  local PATTERN;
BASH_FUNC_nvm_version_dir%%=() {  local NVM_WHICH_DIR;
BASH_FUNC_nvm_version_greater%%=() {  command awk 'BEGIN {
BASH_FUNC_nvm_version_greater_than_or_equal_to%%=() {  command awk 'BEGIN {
BASH_FUNC_nvm_version_path%%=() {  local VERSION;
BASH_FUNC_nvm_wrap_with_color_code%%=() {  local CODE;
BEGIN {

(------- regular env vars with 2 lines with `EOF` -------)

NODE_ENV=development
NVM_BIN=/Users/ppo/.nvm/versions/node/v18.12.1/bin
NVM_CD_FLAGS=
NVM_DIR=/Users/ppo/.nvm
NVM_HOMEBREW=/usr/local/opt/nvm
NVM_INC=/Users/ppo/.nvm/versions/node/v18.12.1/include/node
PATH=/Users/ppo/.nvm/versions/node/v18.12.1/bin:****

(------- more regular env vars -------)

function alen(arr, i, len) { len=0; for(i in arr) len++; return len; }

(------- a lot of lines with a single `}` -------)

Operating system and version:

nvm debug output:

nvm --version: v0.39.3
$TERM_PROGRAM: iTerm.app
$SHELL: /usr/local/bin/bash
$SHLVL: 1
whoami: 'ppo'
${HOME}: /Users/ppo
${NVM_DIR}: '${HOME}/.nvm'
${PATH}: ${NVM_DIR}/versions/node/v18.12.1/bin:/usr/local/sbin:/usr/local/opt/coreutils/libexec/gnubin:/usr/local/bin:/System/Cryptexes/App/usr/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Library/Apple/usr/bin
$PREFIX: ''
${NPM_CONFIG_PREFIX}: ''
$NVM_NODEJS_ORG_MIRROR: ''
$NVM_IOJS_ORG_MIRROR: ''
shell version: 'GNU bash, version 5.2.15(1)-release (x86_64-apple-darwin22.1.0)'
uname -a: 'Darwin 22.2.0 Darwin Kernel Version 22.2.0: Fri Nov 11 02:08:47 PST 2022; root:xnu-8792.61.2~4/RELEASE_X86_64 x86_64 i386 Darwin'
checksum binary: 'sha256sum'
OS version: macOS 13.1 22C65
awk: /usr/bin/awk, awk version 20200816
curl: /usr/bin/curl, curl 7.85.0 (x86_64-apple-darwin22.0) libcurl/7.85.0 (SecureTransport) LibreSSL/3.3.6 zlib/1.2.11 nghttp2/1.47.0
wget: /usr/local/bin/wget, GNU Wget 1.21.3 built on darwin21.3.0.
sed: /usr/bin/sed
cut: /usr/local/opt/coreutils/libexec/gnubin/cut
basename: /usr/local/opt/coreutils/libexec/gnubin/basename
rm: /usr/local/opt/coreutils/libexec/gnubin/rm
mkdir: /usr/local/opt/coreutils/libexec/gnubin/mkdir
xargs: /usr/bin/xargs
git: /usr/local/bin/git, git version 2.39.0
grep: /usr/bin/grep (ggrep --color), grep (BSD grep, GNU compatible) 2.6.0-FreeBSD
nvm current: v18.12.1
which node: ${NVM_DIR}/versions/node/v18.12.1/bin/node
which iojs:
which npm: ${NVM_DIR}/versions/node/v18.12.1/bin/npm
npm config get prefix: ${NVM_DIR}/versions/node/v18.12.1
npm root -g: ${NVM_DIR}/versions/node/v18.12.1/lib/node_modules

nvm ls output:

->     v18.12.1
         system
default -> 18.12.1 (-> v18.12.1)
iojs -> N/A (default)
unstable -> N/A (default)
node -> stable (-> v18.12.1) (default)
stable -> 18.12 (-> v18.12.1) (default)
lts/* -> lts/hydrogen (-> v18.12.1)
lts/argon -> v4.9.1 (-> N/A)
lts/boron -> v6.17.1 (-> N/A)
lts/carbon -> v8.17.0 (-> N/A)
lts/dubnium -> v10.24.1 (-> N/A)
lts/erbium -> v12.22.12 (-> N/A)
lts/fermium -> v14.21.2 (-> N/A)
lts/gallium -> v16.19.0 (-> N/A)
lts/hydrogen -> v18.12.1

How did you install nvm?

Homebrew

Is there anything in any of your profile files that modifies the PATH?

Yes

Note that nvm is unsupported when installed via homebrew; it should only be installed with the install script in the readme.

In this case, it's likely that you have defined a shell alias that clobbers a builtin command, like do or fi or something. I can't know without seeing the contents of your shell profile file.

Thanks @ljharb.
I found the guilty line! set -a (Each variable or function that is created or modified is given the export attribute and marked for export to the environment of subsequent commands)