每次启动终端时我都会收到此消息:
bash: warning: here-document at line 119 delimited by end-of-file (wanted `EOF')
我相信我最近曾尝试安装 Haskell 堆栈,但似乎安装不正确,这可能是警告出现的地方,因为它在此之后才出现。
@乔治运行命令时这是我在终端中看到的,这与我在之前重复评论中提到的同一行。
@John Hi,这些是运行时出现的最后几行:
r libreoffice loweb lobase localc
++++ /etc/bash_completion.d/libreoffice.sh:110:unset _def _dir _file _nosp _minusdd _minusdf
+++ /usr/share/bash-completion/bash_completion:1984:unset i _blacklist_glob
+++ /usr/share/bash-completion/bash_completion:1987:[[ /usr/share/bash-completion/bash_completion != \/\h\o\m\e\/\p\e\a\k\s/.bash_completion ]]
+++ /usr/share/bash-completion/bash_completion:1987:[[ -r /home/peaks/.bash_completion ]]
+++ /usr/share/bash-completion/bash_completion:1989:unset -f have
+++ /usr/share/bash-completion/bash_completion:1990:unset have
+++ /usr/share/bash-completion/bash_completion:1992:set +v
+++ /usr/share/bash-completion/bash_completion:1993:unset BASH_COMPLETION_ORIGINAL_V_VALUE
bash: warning: here-document at line 119 delimited by end-of-file (wanted `EOF')
++ /home/peaks/.bashrc:119:cat
+ /home/peaks/.profile:20:PATH=/home/peaks/bin:/home/peaks/.local/bin:/home/peaks/bin:/home/peaks/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin
@John1024 出现的情况如下:
peaks@system64:~$ awk 'NR==119,NR==130' /home/peaks/.bashrc
cat >> ~/.bashrc <<EOF
export PATH="$HOME/.cabal/bin:/opt/cabal/1.22/bin:/opt/ghc/7.10.3/bin:$PATH"
export PATH="/home/peaks/.cabal/bin:/opt/cabal/1.22/bin:/opt/ghc/7.10.3/bin:/home/peaks/bin:/home/peaks/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin"
peaks@system64:~$
答案1
步骤 1:症状
最初的症状是错误消息:
bash: warning: here-document at line 119 delimited by end-of-file (wanted `EOF')
这告诉我们问题出在第 119 行,但遗憾的是没有告诉我们问题发生时正在运行哪个文件。根据系统配置,交互式 bash 可能会运行大量启动文件中的任何一个。
第 2 步:诊断
要找出哪些 bash 启动文件的哪些行导致问题,可以运行:
PS4='+ $BASH_SOURCE:$LINENO:' bash -xlic ""
这将以诊断模式 ( ) 启动交互式 ( -i
) bash 登录 ( ) shell并运行一个空命令 ( )。bash 提示符设置为在每行输出前加上导致该输出的文件和行。-l
-x
-c ""
PS4
步骤 3:确定问题
运行上述诊断命令,我们发现:
+++ /usr/share/bash-completion/bash_completion:1993:unset BASH_COMPLETION_ORIGINAL_V_VALUE
bash: warning: here-document at line 119 delimited by end-of-file (wanted `EOF')
++ /home/peaks/.bashrc:119:cat
+ /home/peaks/.profile:20:PATH=/home/peaks/bin:/home/peaks/.local/bin:/home/peaks/bin:/home/peaks/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin
这表明此处文档的问题来自文件的第 119 行/home/peaks/.bashrc
相关部分.bashrc
为:
cat >> ~/.bashrc <<EOF
export PATH="$HOME/.cabal/bin:/opt/cabal/1.22/bin:/opt/ghc/7.10.3/bin:$PATH"
export PATH="/home/peaks/.cabal/bin:/opt/cabal/1.22/bin:/opt/ghc/7.10.3/bin:/home/peaks/bin:/home/peaks/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin"
第 119 行cat >> ~/.bashrc <<EOF
有问题。它试图.bashrc
在文件执行时修改文件。在这种情况下,它会在 的末尾附加新的 PATH 定义.bashrc
。显然,该文件最终包含大量此类 PATH 语句,从而严重延迟了 bash 的初始化。
步骤 4:补救措施
可以通过打开编辑器并删除不需要的行来解决该问题。Linux 提供了多种编辑器供您选择。该编辑器vi
保证存在于 POSIX 系统上,但学习难度较高。它 nano
广泛可用,并且对新手来说很好,因为它易于使用。因此,为了解决这个问题,我们可以运行:
nano ~/.bashrc
然后转到问题行并将其删除并保存文件。
或者,我们可以通过运行以下命令来避免学习新的编辑器:
sed -i.bak '119d; 130,$d' ~/.bashrc
此命令会~/.bashrc
就地更新,删除第 119 行并从第 130 行删除文件末尾。为安全起见,原始文件的备份副本~/bashrc
将保存为~/.bashrc.bak
。
答案2
您的.bashrc
文件与我看到的不符,请运行以下命令:
制作备份:
cp ~/.bashrc ~/.bashrc.newbak
在您最喜欢的编辑器中打开它并进行以下更改
gedit ~/.bashrc
,并更改以下几行(我相信是从 119 开始的):你的 .bashrc:
export PATH="$HOME/.cabal/bin:/opt/cabal/1.22/bin:/opt/ghc/7.10.3/bin:$PATH" export PATH="/home/peaks/.cabal/bin:/opt/cabal/1.22/bin:/opt/ghc/7.10.3/bin:/home/peaks/bin:/home/peaks/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin" export PATH="/home/peaks/.cabal/bin:/opt/cabal/1.22/bin:/opt/ghc/7.10.3/bin:/home/peaks/bin:/home/peaks/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin"
要进行的更改,删除
step: 2.1
上面除最后一行之外的所有内容:export PATH="/home/peaks/.cabal/bin:/opt/cabal/1.22/bin:/opt/ghc/7.10.3/bin:/home/peaks/bin:/home/peaks/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin"
保存并关闭编辑器。
检查是否
.bashrc
正常:source ~/.bashrc
如果步骤 3 返回错误,请使用以下命令从备份中恢复:
cat ~/.bashrc.newbak > ~/.bashrc