`fnm env --use-on-cd` emits bash-only `[[ ]]` syntax with no `POSIX` sh option
Author: cherioCreated Sep 4, 2026Updated Sep 4, 2026
Environment: fnm 1.30.0, Ubuntu 24.04, dash (/bin/sh)
In general, any Linux environment where /bin/sh -> dash
Bug
fnm env --use-on-cd generates:
if [[ -f .node-version || -f .nvmrc || -f package.json ]]; then[[ ]] isn't POSIX. Eval'd under dash/sh, it errors and the check silently never runs fnm use:
sh: [[: not foundRepro
#!/bin/sh
eval "$(fnm env --use-on-cd)"
cd .Run with dash script.sh.
Fix
There is a really simple straightforward solution that works everywhere:
# instead of:
if [[ -f .node-version || -f .nvmrc || -f package.json ]]; then
# use:
if [ -f .node-version ] || [ -f .nvmrc ] || [ -f package.json ]; thenValid in POSIX sh and bash/zsh — safe as the default
Source: Schniz/fnm