riywo / ndenv

node.js version manager based on rbenv
304 stars 31 forks source link

Errors under /bin/sh #7

Open l8nite opened 9 years ago

l8nite commented 9 years ago

Looks like the init is doing some bash-specific stuff. I ran into this trying to do some ndenv stuff in a Dockerfile RUN statement (which executes as sh -c)

root@53f25125c2a2:/# sh -c 'eval "$(ndenv init -)"'
sh: 2: eval: source: not found
sh: 5: typeset: not found

Compare this to rbenv:

root@53f25125c2a2:/# sh -c 'eval "$(rbenv init -)"'
root@53f25125c2a2:/#

Here is the rbenv init output:

root@53f25125c2a2:/# sh -c 'rbenv init -'
export PATH="/opt/rbenv/shims:${PATH}"
export RBENV_SHELL=sh
rbenv rehash 2>/dev/null
rbenv() {
  local command
  command="$1"
  if [ "$#" -gt 0 ]; then
    shift
  fi

  case "$command" in
  rehash|shell)
    eval "`rbenv "sh-$command" "$@"`";;
  *)
    command rbenv "$command" "$@";;
  esac
}

And the ndenv init output:

root@53f25125c2a2:/# sh -c 'ndenv init -'
export PATH="/opt/ndenv/shims:${PATH}"
source "/opt/ndenv/libexec/../completions/ndenv.bash"
ndenv rehash 2>/dev/null
ndenv() {
  typeset command
  command="$1"
  if [ "$#" -gt 0 ]; then
    shift
  fi

  case "$command" in
  rehash|shell)
    eval "`ndenv "sh-$command" "$@"`";;
  *)
    command ndenv "$command" "$@";;
  esac
}
kuriyama commented 8 years ago

I experienced the same thing with FreeBSD /bin/sh. After looking at rbenv repo, it's not simple.

In rbenv, they changed from "local" to "typeset" in https://github.com/rbenv/rbenv/commit/3060578e3b346fee7429aa4f0f2542693cb765f9 commit for ksh compatibility.

Then, they back to "local" except ksh with case switching in https://github.com/rbenv/rbenv/commit/5ae2cac088d12fea01054e1f3abbf304b92920b5 commit.

I'm not sure how to fix this in ndenv. Our options (maybe) are:

  1. Sync with recent rbenv repo, but it may causes huge diff.
  2. Just add simple case switch in ndenv-init to output "typeset command" for ksh, "local command" for other shells.
  3. Keep as is and decide not supporting dash and *BSD /bin/sh.