问题:[root@VM_110_99_centos 10.0.0]# source /etc/profile
-bash: /etc/profile:行73: 语法错误: 未预期的文件结尾
文件内容:
# /etc/profile
# System wide environment and startup programs, for login setup
# Functions and aliases go in /etc/bashrc
# It's NOT a good idea to change this file unless you know what you
# are doing. It's much better to create a custom.sh shell script in
# /etc/profile.d/ to make custom changes to your environment, as this
# will prevent the need for merging in future updates.
pathmunge () {
case ":${PATH}:" in
*:"$1":*)
;;
*)
if [ "$2" = "after" ] ; then
PATH=$PATH:$1
else
PATH=$1:$PATH
fi
esac
}
if [ -x /usr/bin/id ]; then
if [ -z "$EUID" ]; then
# ksh workaround
EUID=`/usr/bin/id -u`
UID=`/usr/bin/id -ru`
fi
USER="`/usr/bin/id -un`"
LOGNAME=$USER
MAIL="/var/spool/mail/$USER"
fi
# Path manipulation
if [ "$EUID" = "0" ]; then
pathmunge /usr/sbin
pathmunge /usr/local/sbin
else
pathmunge /usr/local/sbin after
pathmunge /usr/sbin after
fi
HOSTNAME=`/usr/bin/hostname 2>/dev/null`
if [ "$HISTCONTROL" = "ignorespace" ] ; then
export HISTCONTROL=ignoreboth
else
export HISTCONTROL=ignoredups
fi
export PATH USER LOGNAME MAIL HOSTNAME HISTSIZE HISTCONTROL
# By default, we want umask to get set. This sets it for login shell
# Current threshold for system reserved uid/gids is 200
# You could check uidgid reservation validity in
# /usr/share/doc/setup-*/uidgid file
if [ $UID -gt 199 ] && [ "`/usr/bin/id -gn`" = "`/usr/bin/id -un`" ]; then
umask 002
else
umask 022
for i in /etc/profile.d/*.sh ; do
if [ -r "$i" ]; then
if [ "${-#*i}" != "$-" ]; then
. "$i"
else
. "$i" >/dev/null
fi
fi
done #---》这是第72行
我这里执行上面的shell提示是
-bash: test.sh: line 13: syntax error near unexpected token `)'
-bash: test.sh: line 13: ` *:"$1":*)'
截图是这样的:
@魅影独秀: 第73行可能有不可见字符,建议删除一下73行
@dudu: 问题是,删不掉啊。在linux系统上用vim指令进入编辑模式,到达最底部就是done的那行
@魅影独秀: G
到底部,dd
删除
@魅影独秀: 或者sed -i '73d' /etc/profile
@dudu:
还是有点问题
@dudu: 我之前有配过jdk的环境变量,不太清楚之前是怎样操作的了,后来source命令编译就没成功过
@魅影独秀: sh /etc/profile
可以正常运行吗?
@dudu: 报一样的错误
@dudu: 不太懂shell语法,会不会是最后那个循环的问题
@魅影独秀: 最后一个fi
没有与对应的if
对齐
@dudu: 非常感谢你,问题解决了。问题出在第58行,那里的if没有结尾,在62行加上fi。其次就是最后缺少
unset i
unset -f pathmunge
然后编译能够成功。
73行是什么?
– dudu 6年前@dudu: 行的标识,这是第72行
– 魅影独秀 6年前@dudu: 73行是没有的
– 魅影独秀 6年前