Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sort command not found #1227

Closed
MichaelJCole opened this issue Sep 14, 2016 · 21 comments
Closed

sort command not found #1227

MichaelJCole opened this issue Sep 14, 2016 · 21 comments
Labels
needs followup We need some info or action from whoever filed this issue/PR.

Comments

@MichaelJCole
Copy link

MichaelJCole commented Sep 14, 2016

Hi, I'm getting this error:

~/scm/bigSmall/ops/stage/mupx ~/bigSmall/ops/stage/mupx
=====================================================
---- Mupx Deploy for stage ---------------------
-----------------------------------------------------
load
current
v0.10.46
install
/usr/bin/sort
/home/michael/.nvm/nvm.sh: line 748: sort -t. -u -k 1.2: command not found

From this script:

#!/bin/bash
set -e

BUILDFOR="$1"
SERVER="$2"
IFS=',' MUPX_APPS=($3)
CONFDIR=`pwd`

echo "====================================================="
echo "---- Mupx Deploy for $BUILDFOR ---------------------"
echo "-----------------------------------------------------"

echo "load"
source ~/.nvm/nvm.sh
echo "current"
nvm current
echo "install"
which sort
nvm install 0.10.46
echo "update"
npm update -g mupx
echo "done"

Any suggestions?

@ljharb
Copy link
Member

ljharb commented Sep 14, 2016

What does nvm debug output? sort is part of POSIX, so it should be available.

@ljharb ljharb added the needs followup We need some info or action from whoever filed this issue/PR. label Sep 14, 2016
@MichaelJCole
Copy link
Author

MichaelJCole commented Sep 15, 2016

Hey there, I'm on Linux Mint (Ubuntu 14.04).

Yes, it is available - see the which sort output -> /usr/bin/sort

@ljharb
Copy link
Member

ljharb commented Sep 15, 2016

What about type sort, and command sort?

@MichaelJCole
Copy link
Author

☀  type sort                                                      NewMod master
sort is /usr/bin/sort

michael@mc-desktop ~/bigSmall/ops/stage/mupx
☀  command sort                                                   NewMod master
^C

command sort needed to be ctrl-c'd

@MichaelJCole
Copy link
Author

MichaelJCole commented Sep 15, 2016

I'm using version v0.30.1

I tried:

cd ~/.nvm
git pull
git checkout v0.31.7 

But it didn't help :-/

load
current
v0.10.46
install
/usr/bin/sort
sort is /usr/bin/sort
/home/michael/.nvm/nvm.sh: line 1006: sort -t. -u -k 1.2: command not found
Version 'v0.10.46' not found - try `nvm ls-remote` to browse available versions.

@MichaelJCole
Copy link
Author

MichaelJCole commented Sep 15, 2016

So I found a work around. This code was in a called script.

#!/bin/bash
blah
../../deploy-some-apps.sh blah blah blah

Then the error happened in

# deploy-some-apps.sh
nvm install v0.10.46   <----  Error here

But if I moved the nvm install to the outer script it works:

#!/bin/bash
blah
nvm install v0.10.46    <-- works here in script called directly from command line.
../../deploy-some-apps.sh

and

#deploy-some-apps.sh
blah 
blah 
blah

Anyways, thanks for nvm. It's cool.

@ljharb
Copy link
Member

ljharb commented Sep 15, 2016

Glad you figured it out - not sure why it wasn't working :-/

@ljharb ljharb closed this as completed Sep 15, 2016
@MichaelJCole
Copy link
Author

I'm crap at bash, but thinking about it, the environment wasn't getting passed to nvm (PATH to sort).

So probably changing ../../deploy-some-apps.sh to source ../../deploy-some-apps.sh would have fixed it.

@artlawry
Copy link

getting this in v0.32.0 as well. Is there a v0.32.1 coming with this fix in tow?

@ljharb
Copy link
Member

ljharb commented Sep 25, 2016

@artlawry there's no fix yet, since we're still not sure what the problem was. What's your nvm debug output, as well as which sort?

@artlawry
Copy link

This is all on a MacBook Air recently restored to factory and upgraded to Sierra - I'm unsure if this is related to Sierra as I had installed nvm and autoenv a good deal ago on El Capitan before this.

I'm using autoenv (runs nvm use on cd), digging into what the actual nvm command it executes is

cd control
Found '/Users/alawry/dev/brighttag/ui/control/.nvmrc' with version <v5.7.1>
-bash: sort -t. -u -k 1.2,1n -k 2,2n -k 3,3n: command not found
Version 'v5.7.1' not found - try `nvm ls-remote` to browse available versions.

here's proof that v5.7.1 is on my system:

$ nvm use
Found '/Users/alawry/dev/brighttag/ui/control/.nvmrc' with version <v5.7.1>
Now using node v5.7.1 (npm v3.6.0)

Debug information:

$ nvm debug
nvm --version: v0.31.7
$SHELL: /bin/bash
$HOME: /Users/alawry
$NVM_DIR: '$HOME/.nvm'
$PREFIX: ''
$NPM_CONFIG_PREFIX: ''
nvm current: v5.7.1
which node: $NVM_DIR/versions/node/v5.7.1/bin/node
which iojs:
which npm: $NVM_DIR/versions/node/v5.7.1/bin/npm
npm config get prefix: $NVM_DIR/versions/node/v5.7.1
npm root -g: $NVM_DIR/versions/node/v5.7.1/lib/node_modules
$ which sort
/usr/bin/sort
$ type sort
sort is /usr/bin/sort
$ command sort
^C

had to ctrl-c the command sort

@ljharb
Copy link
Member

ljharb commented Sep 25, 2016

Hmm, I haven't tested on Sierra yet since I'm still on El Cap everywhere.

I don't understand why command sort wouldn't be the same as sort for you, since you have no aliases or function overrides. Since this is likely OS-related, can you file a separate issue with all the same debug output?

@artlawry
Copy link

will do

@aegarbutt
Copy link

I've been struggling with this for weeks. From what I can tell, what is happening in this command:

  VERSIONS="$(nvm_echo "${VERSION_LIST}" \
    | command awk -v pattern="${PATTERN-}" -v lts="${LTS-}" '{
        if (!$1) { next }
        if (pattern && tolower($1) !~ tolower(pattern)) { next }
        if (lts == "*" && $10 ~ /^\-?$/) { next }
        if (lts && lts != "*" && tolower($10) !~ tolower(lts)) { next }
        if ($10 !~ /^\-?$/) print $1, $10; else print $1
      }' \
    | nvm_grep -w "${PATTERN:-.*}" \
    | $SORT_COMMAND)"

is that $SORT_COMMAND is not being tokenized properly. Rather, bash was interpreting the entire string (either command sort or command sort -t. -u -k 1.2,1n -k 2,2n -k 3,3n) as the command to be executed.

I'm not entirely sure //why//, but that seems to be the case. I solved this for //me// (probably not portable to all supported shells) by changing $SORT_COMMAND into an array variable.

  local -a SORT_COMMAND_ARGS
  SORT_COMMAND_ARGS=()
  case "${FLAVOR}" in
    node) SORT_COMMAND_ARGS=(-t. -u -k 1.2,1n -k 2,2n -k 3,3n) ;;
  esac

... (Skip a few lines)

  VERSIONS="$(nvm_echo "${VERSION_LIST}" \
    | command awk -v pattern="${PATTERN-}" -v lts="${LTS-}" '{
        if (!$1) { next }
        if (pattern && tolower($1) !~ tolower(pattern)) { next }
        if (lts == "*" && $10 ~ /^\-?$/) { next }
        if (lts && lts != "*" && tolower($10) !~ tolower(lts)) { next }
        if ($10 !~ /^\-?$/) print $1, $10; else print $1
      }' \
    | nvm_grep -w "${PATTERN:-.*}" \
    | command sort ${SORT_COMMAND_ARGS[*]} )"

Not making a pull request because I don't think it's portable, but maybe this will help track down the issue?

@ljharb
Copy link
Member

ljharb commented Jan 28, 2017

@aegarbutt can you open a new issue with your problem, and fill out the issue template? my first suspicion is that you're using zsh and have an interesting zsh option set, but let's flesh that out independently :-)

@aegarbutt
Copy link

aegarbutt commented Jan 28, 2017 via email

@apsoto
Copy link

apsoto commented Apr 26, 2017

I'm running into this on our linux CI server. I don't see any resolution or a follow up issue from @aegarbutt

Was there any resolution ?

@ljharb
Copy link
Member

ljharb commented Apr 26, 2017

@apsoto nope; please file an issue and fill out the template

@apsoto
Copy link

apsoto commented Apr 26, 2017

Hi, I actually found the source of the problem. I'm using 'bash strict mode'.

http://redsymbol.net/articles/unofficial-bash-strict-mode/

The change of the field separator from space to \n\t triggers the problem.

I worked around it by setting the IFS

IFS=$' ' # nvm expects the default field separator
  # DO nvm stuff
IFS=$'\n\t' # reset to use bash strict mode

You still need a separate issue since this ticket is what google sent me to when I searched for the same error?

@aegarbutt
Copy link

(I thought I had sent an email response in finding my problem, but I apparently did not.)

My root cause was an IFS leakage from my bash config. Never actually determined why it only seemed to impact nvm.

@ljharb
Copy link
Member

ljharb commented Apr 27, 2017

@aegarbutt because nvm is sourced in your shell, so it always can be affected by anything you set in your shell.

@apsoto yes, a separate issue about IFS would be great, just because this thread is so long (but it appears that was the OP's issue too)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs followup We need some info or action from whoever filed this issue/PR.
Projects
None yet
Development

No branches or pull requests

5 participants