Linux .bashrc 语法错误:文件意外结束
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/11929705/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
.bashrc syntax error: unexpected end of file
提问by derry30
I am getting an unexpected end of file error. I am not really sure how to fix it.
我收到意外的文件结尾错误。我不确定如何解决它。
# Source global definitions
if [ -f /etc/bashrc ]; then
. /etc/bashrc
fi
# User specific aliases and functions
export PS1='\[\e[0;32m\]\u\[\e[m\] \[\e[1;34m\]\w\[\e[m\] \[\e[1;32m\]$\[\e[m\] \[\e[1;37m\]'
export LS_COLORS='di=35;1'
alias la='ls -lah'
alias cdu='cd /home/hzhang/primary'
#module load gnu-compilers/4.7.0
#module load mvapich3/gnu/1.7
.ls /opt/intel/Compiler/11.1/072/bin/ifortvars.sh intel64
#PATH=$PATH:/home/hzhang/primary/over2.2e/bin_dp:/home/hzhang/primary/foiltest
PATH=$PATH:/opt/overflow/intel/serial/bin_dp/:/home/hzhang/primary/chimera2.1/bin_dp/:/u/primary/hzhang/pegasus/bin_dp
export PATH
ulimit -s unlimited
回答by bitmask
Such syntax errors are really simple to find. At first glance the file looks okay, so I'd suggest you comment out every single line (with #
) and see if the error still manifests.
这样的语法错误真的很容易找到。乍一看该文件看起来不错,所以我建议您注释掉每一行(用#
),看看错误是否仍然存在。
Then just do binary search, that is, comment in the first half of the file. If that works continue with the third quarter (otherwise with the first quarter). And so forth.
然后就做二分查找,也就是在文件的前半部分注释掉。如果这在第三季度继续有效(否则在第一季度)。等等。
回答by tooboring4me
This .bashrc shall have been edited from windows. fromdos .bashrcé to correct this file in order to source it.
此 .bashrc 应已从 Windows 编辑。fromdos .bashrcé 以更正此文件以获取它。
回答by LSDeva
I had the same error due to missing "fi" line. Make sure to omit syntax errors. The original .bashrc is located in /etc/skel/. So just run the following command:
由于缺少“fi”行,我遇到了同样的错误。确保省略语法错误。原始 .bashrc 位于 /etc/skel/。所以只需运行以下命令:
cp /etc/skel/.bashrc ~
cp /etc/skel/.bashrc ~
回答by Simón
I had a similar problem, it turned out to be a missing "}" at the end of a function. I made a backup of the faulty one (in order to have an idea of what my setup was) and then copied the original fine (cp /etc/skel/.bashrc ~) and added the lines again.
我遇到了类似的问题,结果是函数末尾缺少“}”。我备份了错误的(为了了解我的设置是什么),然后复制了原来的(cp /etc/skel/.bashrc ~)并再次添加了这些行。
回答by stu-b-doo
I was facing a similar problem. Using the bash that comes with Windows 10, somehow the line endings had been changed to windows line endings (CRLF). Changing the file back to use unix line endings solved the issue.
我面临着类似的问题。使用 Windows 10 附带的 bash,不知何故,行尾已更改为 Windows 行尾 (CRLF)。将文件改回使用 unix 行尾解决了这个问题。
Convert eh line endings to unix endings and see if that solves the issue. If editing in Vim, enter the command :set fileformat=unix
and save the file. Several other editors have the ability to convert line endings, such as Notepad++or Atom
将 eh 行结尾转换为 unix 结尾,看看是否能解决问题。如果在 Vim 中编辑,输入命令:set fileformat=unix
并保存文件。其他几个编辑器具有转换行尾的能力,例如Notepad++或Atom
回答by Meshu
. . . if ! shopt -oq posix; then if [ -f /usr/share/bash-completion/bash_completion ]; then . /usr/share/bash-completion/bash_completion elif [ -f /etc/bash_completion ]; then . /etc/bash_completion fi FiIn the first line of my terminal i got There is error at the end of the /.bashrc filebut when i change Fito fiit works fine like
. . . 如果 !shopt -oq posix; 然后如果 [ -f /usr/share/bash-completion/bash_completion ]; 然后 。/usr/share/bash-completion/bash_completion elif [ -f /etc/bash_completion ]; 然后 。/etc/bash_completion fi Fi在我终端的第一行,我得到了 /.bashrc 文件末尾有错误,但是当我将Fi更改为fi 时,它工作正常
. . . . if ! shopt -oq posix; then if [ -f /usr/share/bash-completion/bash_completion ]; then . /usr/share/bash-completion/bash_completion elif [ -f /etc/bash_completion ]; then . /etc/bash_completion fi fi
. . . . 如果 !shopt -oq posix; 然后如果 [ -f /usr/share/bash-completion/bash_completion ]; 然后 。/usr/share/bash-completion/bash_completion elif [ -f /etc/bash_completion ]; 然后 。/etc/bash_completion fi fi
回答by I am anonymous
Just open the file from terminal by gedit .bashrc
The document will open ,go to the bottom and see if fi
is missing there,if it is not there add it.Just put "fi" at the left margin at the last and close all the commands with "fi".see here
只需从终端打开文件gedit .bashrc
The document will open ,转到底部看fi
那里是否丢失,如果没有则添加它。只需在最后的左边距放上“fi”并用“关闭所有命令”菲”。看这里