nvm-sh / nvm

Node Version Manager - POSIX-compliant bash script to manage multiple active node.js versions
MIT License
80.35k stars 8.03k forks source link

ZSH: Getting strange `grep: x: Is a directory` in my terminal, as well as unexpected parsing of files #2364

Closed Xananax closed 3 years ago

Xananax commented 3 years ago

Operating system and version:

Arch Linux

nvm debug output:

```sh nvm --version: v0.37.1 $SHELL: /usr/bin/zsh $SHLVL: 3 whoami: 'xananax' ${HOME}: /home/xananax ${NVM_DIR}: '${HOME}/.nvm' ${PATH}: ${NVM_DIR}/versions/node/v12.18.4/bin:/usr/local/sbin:/usr/local/bin:/usr/bin:/var/lib/flatpak/exports/bin:/usr/lib/jvm/default/bin:/usr/bin/site_perl:/usr/bin/vendor_perl:/usr/bin/core_perl $PREFIX: '' ${NPM_CONFIG_PREFIX}: '' $NVM_NODEJS_ORG_MIRROR: '' $NVM_IOJS_ORG_MIRROR: '' shell version: 'zsh 5.8 (x86_64-pc-linux-gnu)' uname -a: 'Linux 5.9.10-arch1-1 #1 SMP PREEMPT Sun, 22 Nov 2020 14:16:59 +0000 x86_64 GNU/Linux' checksum binary: 'sha256sum' OS version: Arch Linux () curl: /usr/bin/curl, curl 7.73.0 (x86_64-pc-linux-gnu) libcurl/7.73.0 OpenSSL/1.1.1h zlib/1.2.11 zstd/1.4.5 libidn2/2.3.0 libpsl/0.21.1 (+libidn2/2.3.0) libssh2/1.9.0 nghttp2/1.41.0 wget: /usr/bin/wget, GNU Wget 1.20.3 built on linux-gnu. git: /usr/bin/git, git version 2.29.2 ls: cannot access 'grep:': No such file or directory grep: grep: aliased to grep --color=auto (grep --color=auto), grep (GNU grep) 3.6 awk: /usr/bin/awk, GNU Awk 5.1.0, API: 3.0 (GNU MPFR 4.1.0, GNU MP 6.2.0) sed: /usr/bin/sed, sed (GNU sed) 4.8 cut: /usr/bin/cut, cut (GNU coreutils) 8.32 basename: /usr/bin/basename, basename (GNU coreutils) 8.32 rm: /usr/bin/rm, rm (GNU coreutils) 8.32 mkdir: /usr/bin/mkdir, mkdir (GNU coreutils) 8.32 xargs: /usr/bin/xargs, xargs (GNU findutils) 4.7.0 nvm current: v12.18.4 which node: ${NVM_DIR}/versions/node/v12.18.4/bin/node which iojs: iojs not found which npm: ${NVM_DIR}/versions/node/v12.18.4/bin/npm npm config get prefix: ${NVM_DIR}/versions/node/v12.18.4 npm root -g: ${NVM_DIR}/versions/node/v12.18.4/lib/node_modules ```

nvm ls output:

```sh -> v12.18.4 v14.11.0 system default -> lts/* (-> v12.18.4) iojs -> N/A (default) unstable -> N/A (default) node -> stable (-> v14.11.0) (default) stable -> 14.11 (-> v14.11.0) (default) lts/* -> lts/erbium (-> v12.18.4) lts/argon -> v4.9.1 (-> N/A) lts/boron -> v6.17.1 (-> N/A) lts/carbon -> v8.17.0 (-> N/A) lts/dubnium -> v10.22.1 (-> N/A) lts/erbium -> v12.18.4 ```

How did you install nvm?

Using the Arch package

What it does is put the completion, binaries, and so on in the right place. You can see the script for it here

After that, I added source /usr/share/nvm/init-nvm.sh to my .zshrc.

This script is just:

[ -z "$NVM_DIR" ] && export NVM_DIR="$HOME/.nvm"
source /usr/share/nvm/nvm.sh
source /usr/share/nvm/bash_completion
source /usr/share/nvm/install-nvm-exec

What steps did you perform?

I updated the package

What happened?

When I open a terminal, I get:

grep: Desktop: Is a directory
grep: Downloads: Is a directory
...etc

This also happens on TTY, with no graphical server running at all.

If I open a terminal in specific directories (in this occurrence an Electron project), I get additional weirdness:

grep: node_modules: Is a directory
grep: out: Is a directory
grep: src: Is a directory
grep: static: Is a directory 
(eval):1: command not found: forge.config.js
nvm is not compatible with the "README.md:- [`forge.config.js`](./forge.config.js): decides which packages are used by Electron Forge. In particular, it sets the exporters (Windows, Mac, Linux, ...)" environment variable: currently set to ".md:- [](./forge.config.js): decides which packages are used by Electron Forge. In particular, it sets the exporters (Windows, Mac, Linux, ...)"
Run `unset README.md:- [\`forge.config.js\`](./forge.config.js): decides which packages are used by Electron Forge. In particular, it sets the exporters (Windows, Mac, Linux, ...)` to unset it.

Of course, the sentence

- [`forge.config.js`](./forge.config.js): decides which packages are used by Electron Forge. In particular, it sets the exporters (Windows, Mac, Linux, ...)

is part of my README.md and describes the project's architecture.

The string forge.config.js only exists in the README.md and as a config key in `package.json.

> grep -R "forge.config.js" --exclude-dir node_modules
package.json:    "forge": "./forge.config.js"
README.md:- [`forge.config.js`](./forge.config.js): decides which packages are used by Electron Forge. In particular, it sets the exporters (Windows, Mac, Linux, ...)

If I remove that sentence from the README, then nvm tells me this:

nvm is not compatible with the "package.json:    "forge": "./forge.config.js"" environment variable: currently set to ".json:    forge: ./forge.config.js"

If I remove that, then I am back to the more "normal" error, which tells me grep: <x>: Is a directory.

Removing only the line in package.json isn't sufficient, however, I have to remove it from the README.md too.

So nvm is deciding on its own to... parse the README.md, extract some specific string for some reason, then eval it? Then decide that there's an environment variable equal to the whole line?

Notice the environment variable's name starts with README.md: ... but it's value is set to .md: ...

I can confirm these issues come from the interaction of nvm and zsh, because:

I don't get any of these lines.

Apart for these annoying notices, nvm is working as expected, as far as I can tell.

I posted this first in https://github.com/nvm-sh/nvm/issues/855

What did you expect to happen?

No output in my terminal

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

I use Zimfw, but I otherwise don't do anything specific.

ljharb commented 3 years ago

Duplicate of #2360.

Xananax commented 3 years ago

I had seen that other issue, but no one mentions parsing a markdown file and extracting env variables from there, so I'm thinking my issue might be two issues. Are you sure it's a duplicate?

ljharb commented 3 years ago

I’m pretty confident - but I’ll reopen it just in case, and ping you when v0.7.2 is released.

ljharb commented 3 years ago

I've gone ahead and reverted #2347, which will be released shortly as v0.7.2. Hopefully that solves the problem.

ljharb commented 3 years ago

v0.7.2 is released. Please file a new issue if there's still problems.