我将 Ubuntu 16.04 升级到了 18.04。升级后,登录时我收到消息
Error found when loading /etc/profile.
错误出现在/usr/share/modules/init/sh
文件第 43 行和第 61 行。但是我不明白为什么会产生这个错误。错误内容如下:
/usr/share/modules/init/sh:eval:line 43: syntax error near unexpected token `('
/usr/share/modules/init/sh:eval:line 43: ` untitled(1) _mlshddbg=" ;;'
/usr/share/modules/init/sh:eval:line 61: export: module: not a function
导致错误的行/usr/share/modules/init/sh
是(第 39 至 43 行):
if [ -n "${_mlIFS+x}" ]; then
IFS=$_mlIFS; unset _mlIFS;
else
unset IFS;
fi;
第 61 行是:
export -f module
我怎样才能解决这个问题?
答案1
shellcheck
在文件上运行/usr/share/modules/init/sh
对第 43 行之前的多行给出了以下建议:
if [ -n "`eval 'echo ${'$_mlv'+x}'`" ]; then
^-- SC2006: Use $(..) instead of legacy `..`. ^-- SC2086: Double quote to prevent globbing and word splitting.
module() { eval `/usr/lib/x86_64-linux-gnu/modulecmd-compat sh $*`; }
^-- SC2046: Quote this to prevent word splitting. ^-- SC2006: Use $(..) instead of legacy `..`. ^-- SC2048: Use "$@" (with quotes) to prevent whitespace problems. ^-- SC2086: Double quote to prevent globbing and word splitting.
上述建议可以按以下方式纳入:
if [ -n "$(eval 'echo ${"$_mlv"+x}')" ]; then
module() { eval "$(/usr/lib/x86_64-linux-gnu/modulecmd-compat sh "$*")"; }