Skip to content

Shell inference fails on commands (symlinks) invoked with trailing slash and paths with spaces #1482

@andrewflbarnes

Description

@andrewflbarnes

When a shell is invoked with a trailing slash on symlinks, inference fails. Obviously this is a little weird, but possible - I had this recently with a typo when defining my IntelliJ shell as /opt/homebrew/bin/bash/ instead of /opt/homebrew/bin/bash.

This can also cause shell inference to be wrong e.g. you start a zsh shell from a bash shell.

Reproductions at bottom.

I believe this is caused by these lines which perform a split on / and takes the last entry regardless of whether it is empty or not.

Ultimately I get how this can be viewed as user error but it might be nice to either

  • next_back to the last non blank entry
  • emit a warning log/message that a command with a trailing slash was found and what that full command was

Might also be nice to have a debug log telling you what shell was inferred. RUST_LOG=debug fnm env will show commands which aren't supported shells ([2025-11-28T11:40:32Z DEBUG fnm::shell::infer] binary is not a supported shell: "") but not the command or shell which was successfully inferred:

# succesfully inferred as bash
$ RUST_LOG=debug fnm env >/dev/null 
[2025-11-28T11:41:51Z DEBUG fnm::shell::infer] binary is not a supported shell: "fnm"
[2025-11-28T11:41:51Z DEBUG fnm::shell::infer] binary is not a supported shell: ""

Shell inference fails in IntelliJ

$ ls -l /opt/homebrew/bin/bash
lrwxr-xr-x  1 xxxxxx  admin  29 16 Jul 16:11 /opt/homebrew/bin/bash -> ../Cellar/bash/5.3_1/bin/bash

$ ls -l /opt/homebrew/bin/bash/
-r-xr-xr-x  1 xxxxxx  xxxxxx  896992 16 Jul 16:11 /opt/homebrew/bin/bash/

$ pid=$$; while [ -n "$pid" ]; do read pid prog <<< "$(ps -o ppid,comm -p $pid | awk 'NR == 2 {print}')"; echo $pid $prog; done
3634 /opt/homebrew/bin/bash
1 /Users/xxxxxx/Applications/IntelliJ IDEA Ultimate.app/Contents/MacOS/idea
0 /sbin/launchd

$ fnm env
export PATH="/Users/xxxxxx/.local/state/fnm_multishells/20234_1764328797882/bin":"$PATH"
export FNM_MULTISHELL_PATH="/Users/xxxxxx/.local/state/fnm_multishells/20234_1764328797882"
export FNM_VERSION_FILE_STRATEGY="local"
export FNM_DIR="/Users/xxxxxx/.local/share/fnm"
export FNM_LOGLEVEL="info"
export FNM_NODE_DIST_MIRROR="https://artifactory.awstrp.net/artifactory/nodejs/"
export FNM_COREPACK_ENABLED="false"
export FNM_RESOLVE_ENGINES="true"
export FNM_ARCH="arm64"

# replace current process with shell started with trailing slash
# or just define the terminal shell with a trailing slash
$ exec /opt/homebrew/bin/bash/

# notice second DEBUG line
$ RUST_LOG=debug fnm env
[2025-11-28T11:24:07Z DEBUG fnm::shell::infer] binary is not a supported shell: "fnm"
[2025-11-28T11:24:07Z DEBUG fnm::shell::infer] binary is not a supported shell: ""
[2025-11-28T11:24:07Z DEBUG fnm::shell::infer] binary is not a supported shell: "IntelliJ"
[2025-11-28T11:24:07Z DEBUG fnm::shell::infer] binary is not a supported shell: "launchd"
[2025-11-28T11:24:07Z DEBUG fnm::shell::infer::unix] Can't read process info: entity not found
error: Can't infer shell!
fnm can't infer your shell based on the process tree.
Maybe it is unsupported? we support the following shells:
* bash
* zsh
* fish
* powershell                                                                                                                                                                                                                        

$ pid=$$; while [ -n "$pid" ]; do read pid prog <<< "$(ps -o ppid,comm -p $pid | awk 'NR == 2 {print}')"; echo $pid $prog; done
3634 /opt/homebrew/bin/bash/
1 /Users/xxxxxx/Applications/IntelliJ IDEA Ultimate.app/Contents/MacOS/idea
0 /sbin/launchd

Shell inference incorrect

# start bash shell then
$ ln -s /bin/zsh zsh

$ ./zsh/

xxxxxx@xxxxxx ~ % fnm completions | grep -q BASH && echo bash completions || echo zsh completions
bash completions

xxxxxx@xxxxxx ~ % fnm completions --shell=zsh | grep -q BASH && echo bash completions || echo zsh completions
zsh completions

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions