首页新闻找找看学习计划

Linux的 /etc/profile文件出现问题,求解

-1
悬赏园豆:10 [已解决问题] 解决于 2018-04-29 14:23

问题:[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行

甜珊贝奇的主页 甜珊贝奇 | 初学一级 | 园豆:118
提问于:2018-04-29 10:17

73行是什么?

dudu 1年前

@dudu: 行的标识,这是第72行

魅影独秀 1年前

@dudu: 73行是没有的

魅影独秀 1年前
< >
分享
最佳答案
0

我这里执行上面的shell提示是

-bash: test.sh: line 13: syntax error near unexpected token `)'
-bash: test.sh: line 13: `    *:"$1":*)'
收获园豆:10
dudu | 高人七级 |园豆:39845 | 2018-04-29 11:08

截图是这样的:

甜珊贝奇 | 园豆:118 (初学一级) | 2018-04-29 11:14

@魅影独秀: 第73行可能有不可见字符,建议删除一下73行

dudu | 园豆:39845 (高人七级) | 2018-04-29 11:17

@dudu: 问题是,删不掉啊。在linux系统上用vim指令进入编辑模式,到达最底部就是done的那行

甜珊贝奇 | 园豆:118 (初学一级) | 2018-04-29 11:20

@魅影独秀: G到底部,dd删除

dudu | 园豆:39845 (高人七级) | 2018-04-29 11:23

@魅影独秀: 或者sed -i '73d' /etc/profile

dudu | 园豆:39845 (高人七级) | 2018-04-29 11:25

@dudu: 

还是有点问题

甜珊贝奇 | 园豆:118 (初学一级) | 2018-04-29 11:29

@dudu: 我之前有配过jdk的环境变量,不太清楚之前是怎样操作的了,后来source命令编译就没成功过

甜珊贝奇 | 园豆:118 (初学一级) | 2018-04-29 11:30

@魅影独秀: sh /etc/profile可以正常运行吗?

dudu | 园豆:39845 (高人七级) | 2018-04-29 11:33

@dudu: 报一样的错误

甜珊贝奇 | 园豆:118 (初学一级) | 2018-04-29 11:34

@dudu: 不太懂shell语法,会不会是最后那个循环的问题

甜珊贝奇 | 园豆:118 (初学一级) | 2018-04-29 11:38

@魅影独秀: 最后一个fi没有与对应的if对齐

dudu | 园豆:39845 (高人七级) | 2018-04-29 11:41

@dudu: 非常感谢你,问题解决了。问题出在第58行,那里的if没有结尾,在62行加上fi。其次就是最后缺少

unset i

unset -f pathmunge

然后编译能够成功。

甜珊贝奇 | 园豆:118 (初学一级) | 2018-04-29 14:20
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册