1

I was installing ruby on rails along with homebrew the other day and was following a step by step list of what to do. I now have this bash syntax error every time I enter the terminal:

-bash: /Users/briggsmcknight/.bash_profile: line 6: syntax error near unexpected token `source'
-bash: /Users/briggsmcknight/.bash_profile: line 6: `if which rbenv > /dev/null; then eval "$(rbenv init -)"; fi source /Users/briggsmcknight/.bash_profile'

Could I get a small step by step breakdown of what I should do to fix this? I believe the syntax error is by "fi" or "source", but do I just retype it again or what?

bmike
  • 235,889

3 Answers3

1

Edit the file with a GUI program e.g. TextEdit

Open TextEdit and select the home directory. .bash_profile is hidden so instead of a simple selection then you might have to hit CmdShift. to show .bash_profile When saving delete the .txt ending TextEdit adds or alter TextEdits's preferences.

mmmmmm
  • 30,160
1

Edit the file with a GUI app like TextEdit or TextWrangler - I recommend the latter.

Open the invisible file .bash_profile in your home folder either with TextEdit by hitting CmdShift. or with TextWrangler by checking the button "Show hidden items" in the open dialog.

Remove all if which rbenv > /dev/null; then eval "$(rbenv init -)"; fi source /Users/briggsmcknight/.bash_profile related lines and only leave eval "$(rbenv init -)" and your other mods in the file.

Save the file as .bash_profile (without any suffix like txt or rtf).

Relaunch Terminal.


You mustn't source .bash_profile in the file .bash_profile itself (without a proper if/then/else statement) because you will either get an error or a loop.

klanomath
  • 66,391
  • 9
  • 130
  • 201
0

The simplest step might be to move the hidden file to your desktop and start over making that file.

If you're OK editing the file - perhaps using nano - you can delete the line 6 or comment it out by putting a # before the first character on that line and saving the file.

/usr/sbin/nano ~/.bash_profile

To just start over and get a working terminal:

/bin/mv ~/.bash_profile ~/Desktop/bash_profile.txt
bmike
  • 235,889
  • How do you move the file? It is probably hidden and so not visible in Finder – mmmmmm Dec 08 '16 at 20:12
  • @Mark yup - that's why the mv command to remove the leading . ; - ) Also - you still get a prompt when there's an error in the startup shells. Just type the letters above (mv is best to do first if you're not sure if you can edit it in shape) and then open a new terminal to test your work. – bmike Dec 08 '16 at 20:24
  • 1
    Awesome it worked! Much appreciated bmike. – CoderBriggs Dec 09 '16 at 23:06