鱼不接受命令:设置:警告:$PATH 条目无效

Fish not accepting commands: set: Warning: $PATH entry is not valid

发生了一些愚蠢的事情。我试图在 config.fish 文件中添加一些内容来更改系统范围的 $PATH 变量。我知道,我可能应该先阅读文档,但我想我知道我在做什么。嗯。

更具体地说我做了什么:我在 /etc/fish 中打开了 config.fish 文件并添加了 export PATH=$PATH:/usr/local/gradle-4.5.1/bin 行以将 gradle 添加到我的 PATH 变量中.大错,因为现在我的控制台不再接受任何东西,每当我打开控制台时我都会得到以下信息 window:我现在的问题是:我可以在没有控制台的情况下以某种方式恢复更改,还是唯一的解决方案是重新安装我的 OS?

set: Warning: $PATH entry "/home/david/.local/bin" is not valid (Datei oder Verzeichnis nicht gefunden)
/usr/share/fish/functions/__fish_pwd.fish (Zeile 1): 
uname
^
Befehlsersetzungsblock
    called on line -1 of file /usr/share/fish/functions/__fish_pwd.fish

from sourcing file /usr/share/fish/functions/__fish_pwd.fish
    called on standard input

Befehlsersetzungsblock
    called on standard input

Befehlsersetzungsblock
    called on standard input

/usr/share/fish/functions/__fish_pwd.fish (Zeile 1): switch: Erwartete genau ein Argument, erhielt 0

switch (uname)
       ^
from sourcing file /usr/share/fish/functions/__fish_pwd.fish
    called on standard input

Befehlsersetzungsblock
    called on standard input

Befehlsersetzungsblock
    called on standard input

fish: 
echo $_ " "; __fish_pwd
             ^
Befehlsersetzungsblock
    called on standard input

~/.config/fish/functions/fish_greeting.fish (Zeile 1): 
set fish_greeting | figlet -f lean "Hi  David"
                    ^
Unbekannte Funktion 'fish_greeting'
    called on line 142 of file /usr/share/fish/functions/__fish_config_interactive.fish

Unbekannte Funktion '__fish_config_interactive'
    called on line 216 of file /usr/share/fish/config.fish

Unbekannte Funktion '__fish_on_interactive'
    called on standard input

in event handler: handler for generic event 'fish_prompt'

Befehl »tty« ist unter »/usr/bin/tty« verfügbar
Der Befehl konnte nicht gefunden werden, weil »/usr/bin« nicht Teil der Umgebungsvariable PATH ist.
tty: Befehl nicht gefunden.
~/.config/fish/functions/fish_prompt.fish (Zeile 3): 
    tty | string match -q -r tty
    ^
Unbekannte Funktion 'fish_prompt'
    called on standard input

Befehlsersetzungsblock
    called on standard input

Befehl »hostname« ist unter »/bin/hostname« verfügbar
Der Befehl konnte nicht gefunden werden, weil »/bin« nicht Teil der Umgebungsvariable PATH ist.
hostname: Befehl nicht gefunden.
/usr/share/fish/functions/prompt_hostname.fish (Zeile 1): 
hostname | string split '.'
^
Befehlsersetzungsblock
    called on line -1 of file /usr/share/fish/functions/prompt_hostname.fish

from sourcing file /usr/share/fish/functions/prompt_hostname.fish
    called on line 2 of file ~/.config/fish/functions/fish_prompt.fish

Befehlsersetzungsblock
    called on line 0 of file ~/.config/fish/functions/fish_prompt.fish

Befehlsersetzungsblock
    called on line 0 of file ~/.config/fish/functions/fish_prompt.fish

Unbekannte Funktion 'fish_prompt'
    called on standard input

Befehlsersetzungsblock
    called on standard input

Befehl »sed« ist unter »/bin/sed« verfügbar
Der Befehl konnte nicht gefunden werden, weil »/bin« nicht Teil der Umgebungsvariable PATH ist.
sed: Befehl nicht gefunden.
~/.config/fish/functions/fish_prompt.fish (Zeile 1): 
pwd|sed "s=$HOME=~="
    ^
Befehlsersetzungsblock
    called on line 0 of file ~/.config/fish/functions/fish_prompt.fish

Unbekannte Funktion 'fish_prompt'
    called on standard input

Befehlsersetzungsblock
    called on standard input

Befehl »date« ist unter »/bin/date« verfügbar
Der Befehl konnte nicht gefunden werden, weil »/bin« nicht Teil der Umgebungsvariable PATH ist.
date: Befehl nicht gefunden.
~/.config/fish/functions/fish_prompt.fish (Zeile 1): 
date +%X
^
Befehlsersetzungsblock
    called on line 0 of file ~/.config/fish/functions/fish_prompt.fish

Unbekannte Funktion 'fish_prompt'
    called on standard input

Befehlsersetzungsblock
    called on standard input

__fish_pwd: Befehl nicht gefunden.
fish: 
echo $_ " "; __fish_pwd
             ^
Befehlsersetzungsblock
    called on standard input

您没有在 fish 配置文件中使用 bash 语法。在鱼中,变量包含 个值列表 。 PATH 变量不是以冒号分隔的字符串。

您想这样做而不是将目录附加到列表中:

set PATH $PATH /usr/local/gradle-4.5.1/bin

https://fishshell.com/docs/current/tutorial.html#tut_path

你没有意识到,或者暂时忘记的是,在 fish 中 PATH 实际上是一个数组。它不是像 bash 中那样的单个冒号分隔的目录字符串。在 fish 中,当你将一个数组连接到另一个字符串时,你会得到一个笛卡尔积。假设您首先执行了 export PATH=/dir1:/dir2(使用 bash 表示法)。在 fish 中相当于 set -gx PATH /dir1 /dir2,一个有两个元素的数组 var。现在做这个

for x in PATH=$PATH:/dir3
    echo $x
end

你认为会回显什么?这将被回显:

PATH=/dir1:/dir3
PATH=/dir2:/dir3

这就是为什么您的 PATH 现在在您登录时或多或少没用了。

错误来自您的 fish_prompt 函数,因为它找不到构建提示符所需的任何命令。但是您仍然应该能够输入命令。尝试将您的路径设置为理智的价值。只是 copy/paste 这个:

set -gx PATH /bin /usr/bin /usr/local/bin

这应该可以使您使用的大部分命令再次可用。如果您的编辑器不在这些目录之一中,也包括它的目录​​。现在您应该可以编辑 config.fish 文件了。

P.S., fish中不要使用export命令。它只是一个函数,充当 set 的薄包装。在漫长的 运行 学习鱼的方法中,你会过得更好。

can I revert the change somehow without a console or is the only solution a reinstallation of my OS?

重新安装完全矫枉过正。

Fish 应该仍然可以接受命令,只是您的提示中有太多命令,因此很难查看 输出。

谢天谢地,许多 Linux 发行版上的 $PATH 非常简单,大多数应用程序都在 /usr/bin 中。所以 set -gx PATH /usr/bin 应该会让您进入可以编辑 config.fish 以消除错误的状态。

或者您可以在 fish 命令中使用绝对路径,例如/usr/bin/sudo /usr/bin/nano /etc/fish/config.fish 应该用你的 config.fish 打开 nano。

或者您可以在图形文本编辑器中打开您的 config.fish,该编辑器能够编辑 root 拥有的文件(例如,Kate 只是在您尝试保存时询问您的密码)

或者您可以在终端中更改 "shell" 或 "profile" 设置 - 他们不需要打开您配置的用户 shell,他们通常也可以打开任意程序,就像一个不同的 shell。