10

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 
Pavan Manjunath
  • 27,404
  • 12
  • 99
  • 125
derry30
  • 241
  • 2
  • 3
  • 7
  • 2
    Nothing apparent in that file, though `.ls` looks odd. Check `/etc/bashrc` – geirha Aug 13 '12 at 07:42
  • 1
    ... and assuming the `.ls` is typo only here, in the question, check the `.../ifortvars.sh` too. And you might want to enclose `$PATH` in double quotes, in case a PATH element contains some special characters (like brackets). – fork0 Aug 13 '12 at 08:11
  • as @tooboring4me mentions check if all lines including the last end in `\n` – mnagel Aug 01 '13 at 12:36
  • 1
    // , .bashrc loads several other files, like .bash_aliases. Check here for an example of this error that was fixed by editing another file: http://stackoverflow.com/questions/31211571/bashrc-error-bash-home-jason-bashrc-line-115-syntax-error-unexpected-end – Nathan Basanese Jul 03 '15 at 18:56

8 Answers8

20

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:

cp /etc/skel/.bashrc ~

LSDeva
  • 444
  • 4
  • 8
11

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.

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

stu0292
  • 471
  • 4
  • 7
  • 1
    Thanks for your help on this. It has worked for me. I have cross-posted your answer to https://stackoverflow.com/questions/6366530/bash-syntax-error-unexpected-end-of-file/49226909#49226909. Hope you don't mind. – Jay Killeen Mar 12 '18 at 01:26
  • 1
    This was the solution for me. Very good observations and suggestion. – Paul Dec 11 '20 at 19:09
4

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.

bitmask
  • 32,434
  • 14
  • 99
  • 159
1

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.

Simón
  • 11
  • 1
1

I had the same issue because i made some changes in my .bashcr file and messed up the terminal. Follow command fixed my issue:

ecp /etc/skel/.bashrc ~
סטנלי גרונן
  • 2,917
  • 23
  • 46
  • 68
0

This .bashrc shall have been edited from windows. fromdos .bashrcé to correct this file in order to source it.

  • Can you provide some more detailed information, coz only a few would understand this... – NREZ Aug 01 '13 at 12:54
-1

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

-3

. . . 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 In the first line of my terminal i got There is error at the end of the /.bashrc file but when i change Fi to fi it works fine like

. . . . 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

Meshu
  • 35
  • 1
  • 5