volta-cli / volta

Volta: JS Toolchains as Code. ⚡
https://volta.sh
Other
11.02k stars 231 forks source link

Error in fish shell: env: ‘command’: No such file or directory #454

Closed aeons closed 5 years ago

aeons commented 5 years ago

When running volta in fish shell right after a clean install I get the following error:

env: ‘command’: No such file or directory

I think it stems from the fact that command is a shell builtin and env expects an executable.

Fish version: 3.0.2 Volta version: 0.5.2

charlespierce commented 5 years ago

Hi @aeons, thanks for reporting this! I'm not an expert on Fish, but could you provide a little more information about your environment? What OS are you using? Do you have any unusual settings in your config.fish?

If you have the chance, could you try a small edit to the ~/.volta/load.fish file, based on an answer in the fish faq? On line 14, make the following changes:

    # Forward the arguments to the Volta executable.
-    env VOLTA_SHELL=fish command "$VOLTA_ROOT/volta" $argv
+    begin
+        set -lx VOLTA_SHELL "fish"
+        command "$VOLTA_ROOT/volta" $argv
+    end
    set EXIT_CODE $status

Then re-open your shell and try running volta again.

cc @chriskrycho May know more about what is happening here.

dfreeman commented 5 years ago

I think command is unnecessary if you're running with env, since env is provided by the host OS rather than fish and therefore doesn't know about builtins anyway.

@aeons you might also give the following a try:

     # Forward the arguments to the Volta executable.
-    env VOLTA_SHELL=fish command "$VOLTA_ROOT/volta" $argv
+    env VOLTA_SHELL=fish "$VOLTA_ROOT/volta" $argv
     set EXIT_CODE $status

Given that env is unaware of builtins, I was actually a bit surprised to see env ... command ... working on my own system at all, but on macOS it turns out there are alias scripts for a bunch of POSIX shell builtins (including command) hanging out in /usr/bin.

These scripts run via /bin/sh and pass through their arguments to that shell's corresponding builtin:

#!/bin/sh
# $FreeBSD: src/usr.bin/alias/generic.sh,v 1.2 2005/10/24 22:32:19 cperciva Exp $
# This file is in the public domain.
builtin `echo ${0##*/} | tr \[:upper:] \[:lower:]` ${1+"$@"}

Given the FreeBSD note in the header, I'm guessing that may not be standard on other platforms (e.g. Linux), which would lead to the error @aeons described.

aeons commented 5 years ago

Not on that machine atm, but both of those fixes look correct. Using env for setting environment for one command works fine usually, it's just because command is a shell builtin.