0

I am fairly new to Ubuntu, and did a little more messing around than I should have. I was reading a guide on downloading the Oracle 8 JDK and it said to change the last few lines of the /etc/profile file. It popped up with an error after I did this and now I can't figure out how to change it back.

bash: /etc/profile: line 25: syntax error near unexpected token fi' bash: /etc/profile: line 25:fi'

That is the error that pops up. This is what the /etc/profile file looks like:

# /etc/profile: system-wide .profile file for the Bourne shell (sh(1))
# and Bourne compatible shells (bash(1), ksh(1), ash(1), ...).

if [ "$PS1" ]; then
  if [ "$BASH" ] && [ "$BASH" != "/bin/sh" ]; then
    # The file bash.bashrc already sets the default PS1.
    # PS1='\h:\w\$ '
    if [ -f /etc/bash.bashrc ]; then
      . /etc/bash.bashrc
    fi
  else
    if [ "`id -u`" -eq 0 ]; then
      PS1='# '
    else
      PS1='$ '
    fi
  fi
fi

if [ -d /etc/profile.d ]; then
  for i in /etc/profile.d/*.sh; do
    if [ -r $i ]; then
      . $i
    fi
fi

JAVA_HOME=/usr/lib/jvm/java-8-oracle
PATH=$PATH:$HOME/BIN:$JAVA_HOME/bin
export JAVA_HOME
export PATH

I don't know how to read this or how to fix it and I was stupid for trying to edit it in the first place, without knowing what I'm doing, but any advice on how to fix it would be appreciated. Thank you!

4

The for conditional construct ends in done, which is missing in your case.

Check the ^^^^ mark below:

if [ -d /etc/profile.d ]; then
  for i in /etc/profile.d/*.sh; do
    if [ -r $i ]; then
      . $i
    fi
  done  
  ^^^^  
fi
  • Seems were both were pretty quick with this one :) – Videonauth May 31 '16 at 6:04
5

The part here:

if [ -d /etc/profile.d ]; then
  for i in /etc/profile.d/*.sh; do
    if [ -r $i ]; then
      . $i
    fi
fi

has to look like this:

if [ -d /etc/profile.d ]; then
  for i in /etc/profile.d/*.sh; do
    if [ -r $i ]; then
      . $i
    fi
  done
fi
  • It worked, thank you! Does everything else look good, then. So that I can leave it alone until I know what I'm doing, without any errors? – mrmojorisin2794 May 31 '16 at 6:06
  • Looks legit so far I can see :) you should mark the answer of heemayl as correct one by ticking the checkmark beside his answer and maybe give me an up vote, his answer is more into detail what was wrong. – Videonauth May 31 '16 at 6:07
  • I tried, it wouldn't let me vote because my account is so new. I do appreciate the response, though. Thanks again! – mrmojorisin2794 May 31 '16 at 6:37
0

I had a similar problem on my system a few days ago after I installed JVE1.8 and JDK1.8. Make sure the # symbols in front of /etc/profile(line 1) and and Bourne(line 2) are present as well as the done in between the fi commands at the end are present.

If after that, it still gives an error, try adding unset i above the done command.

If it still gives an error, try adding unset i above the done command.

# /etc/profile: system-wide .profile file for the Bourne shell (sh(1))
# and Bourne compatible shells (bash(1), ksh(1), ash(1), ...).

if [ "$PS1" ]; then
  if [ "$BASH" ] && [ "$BASH" != "/bin/sh" ]; then
    # The file bash.bashrc already sets the default PS1.
    # PS1='\h:\w\$ '
    if [ -f /etc/bash.bashrc ]; then
      . /etc/bash.bashrc
    fi
  else
    if [ "`id -u`" -eq 0 ]; then
      PS1='# '
    else
      PS1='$ '
    fi
  fi
fi

if [ -d /etc/profile.d ]; then
  for i in /etc/profile.d/*.sh; do
    if [ -r $i ]; then
      . $i
JAVA_HOME=/usr/lib/jvm/java-8-oracle
PATH=$PATH:$HOME/BIN:$JAVA_HOME/bin
export JAVA_HOME
export PATH
    fi
done
fi

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.