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?

marked as duplicate by user151019, Allan, fsb, bmike Apr 5 '17 at 21:55

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • Can You paste first 7 lines of your .bash_profile file? – Mateusz Szlosek Dec 8 '16 at 19:58
  • @MateuszSzlosek He can't as he can't get a command line prompt – user151019 Dec 8 '16 at 20:17
  • @BriggsMcnight do you end up with a prompt in the terminal or does the shell exit? – user151019 Dec 8 '16 at 20:18
  • He can open it via TextEdit.app (If file is hidden, there's a shortcut to see it Open File dialog: CMD+SHIFT+. <dot> ) – Mateusz Szlosek Dec 8 '16 at 20:19
  • @MateuszSzlosek I had forgotten the key shortcut – user151019 Dec 8 '16 at 20:43
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
  • How do you move the file? It is probably hidden and so not visible in Finder – user151019 Dec 8 '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 8 '16 at 20:24
  • 1
    Awesome it worked! Much appreciated bmike. – CoderBriggs Dec 9 '16 at 23:06
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.

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.

Not the answer you're looking for? Browse other questions tagged .