我对 Ubuntu 还不熟悉,而且做了一些不该做的事情。我读了一篇关于下载 Oracle 8 JDK 的指南,它说要更改 /etc/profile 文件的最后几行。我这样做之后,它弹出了一个错误,现在我不知道如何改回来。
bash:/etc/profile:第 25 行:意外标记
fi' bash: /etc/profile: line 25:
fi'附近有语法错误
这就是弹出的错误。/etc/profile 文件如下所示:
# /etc/profile: system-wide .profile file for the Bourne shell (sh(1))
# and Bourne compatible shells (bash(1), ksh(1), ash(1), ...).
if [ "$PS1" ]; then
if [ "$BASH" ] && [ "$BASH" != "/bin/sh" ]; then
# The file bash.bashrc already sets the default PS1.
# PS1='\h:\w\$ '
if [ -f /etc/bash.bashrc ]; then
. /etc/bash.bashrc
fi
else
if [ "`id -u`" -eq 0 ]; then
PS1='# '
else
PS1='$ '
fi
fi
fi
if [ -d /etc/profile.d ]; then
for i in /etc/profile.d/*.sh; do
if [ -r $i ]; then
. $i
fi
fi
JAVA_HOME=/usr/lib/jvm/java-8-oracle
PATH=$PATH:$HOME/BIN:$JAVA_HOME/bin
export JAVA_HOME
export PATH
我不知道如何阅读或修复它,而且我一开始就试图编辑它,却不知道我在做什么,真是太愚蠢了,但如果能提供任何关于如何修复它的建议,我将不胜感激。谢谢!
答案1
这里的部分:
if [ -d /etc/profile.d ]; then
for i in /etc/profile.d/*.sh; do
if [ -r $i ]; then
. $i
fi
fi
看起来像这样:
if [ -d /etc/profile.d ]; then
for i in /etc/profile.d/*.sh; do
if [ -r $i ]; then
. $i
fi
done
fi
答案2
条件结构for
以 结尾done
,而您的情况下却缺少这个结尾。
检查^^^^
下面的标记:
if [ -d /etc/profile.d ]; then
for i in /etc/profile.d/*.sh; do
if [ -r $i ]; then
. $i
fi
done
^^^^
fi
答案3
几天前,我在安装了 JVE1.8 和 JDK1.8 后,系统上也出现了类似的问题。确保(第 1 行) 和(第 2 行)#
前面的符号以及末尾命令之间的符号都存在。/etc/profile
and Bourne
done
fi
如果之后仍然出现错误,请尝试在命令unset i
上方添加done
。
如果仍然出现错误,请尝试在命令unset i
上方添加done
。
# /etc/profile: system-wide .profile file for the Bourne shell (sh(1))
# and Bourne compatible shells (bash(1), ksh(1), ash(1), ...).
if [ "$PS1" ]; then
if [ "$BASH" ] && [ "$BASH" != "/bin/sh" ]; then
# The file bash.bashrc already sets the default PS1.
# PS1='\h:\w\$ '
if [ -f /etc/bash.bashrc ]; then
. /etc/bash.bashrc
fi
else
if [ "`id -u`" -eq 0 ]; then
PS1='# '
else
PS1='$ '
fi
fi
fi
if [ -d /etc/profile.d ]; then
for i in /etc/profile.d/*.sh; do
if [ -r $i ]; then
. $i
JAVA_HOME=/usr/lib/jvm/java-8-oracle
PATH=$PATH:$HOME/BIN:$JAVA_HOME/bin
export JAVA_HOME
export PATH
fi
done
fi