12

When opening terminal, this line shows every time:

-bash: :wq: command not found

How can I stop it from appearing every time Terminal opens ?

3
  • 4
    When in terminal type cat ~/.bash_profile or cat ~/.bashrc and paste it here.
    – Tomek Brek
    Commented Nov 13, 2019 at 11:21
  • 4
    sed -i '/:wq/d' ~/.bash* should fix it ;)
    – I.Am.A.Guy
    Commented Nov 14, 2019 at 5:46
  • @I.Am.A.Guy please add that as an Answer.
    – pkamb
    Commented Nov 18, 2019 at 7:46

2 Answers 2

34

It looks like there exists a line :wq in one of your shell’s profile files, such as ~/.bash_profile, which was probably added as a failed attempt at quitting Vim when editing such a file.

To edit the bash profile with TextEdit, run open -e ~/.bash_profile in Terminal. Edit the file to remove the :wq line only. Save it, quit TextEdit and restart Terminal to see changes. You might want to make a copy of the file in case you're worried: cp ~/.bash_profile ~/.bash_profile.bak.

If you don’t want to use Terminal at all, see this answer How to add the PATH for mysql bin on Mac? with instructions on how to edit a profile file only using GUI.

8
  • 1
    What does this question have to do with MySQL?
    – Barmar
    Commented Nov 13, 2019 at 19:10
  • 4
    @Barmar Nothing but ankii added the link as more information on editing the bash profile file using GUI.
    – grg
    Commented Nov 13, 2019 at 19:24
  • 2
    Not adding much but instead of closing and re-opening the terminal, you can just run source .bashrc which should re-source the file, and even give you the error again in case you haven't yet fixed it (IIRC anyway)
    – QuickishFM
    Commented Nov 13, 2019 at 22:07
  • 2
    @QuickishFM I reopen Terminal faster than I can type ;-)
    – anki
    Commented Nov 14, 2019 at 3:44
  • 1
    @QuickishFM: But then your bash session has the effects of two runs of slight variations of your .bashrc, which could cause weird problems. Opening a new terminal will usually lead to a cleaner state. Commented Nov 14, 2019 at 5:11
2

You messed up when editing .bash_profile with the 'vi' editor aka 'vim'.

You did your writing in insert mode, then when you finished, you were supposed to hit esc to exit insert mode, then : w q for command, write and quit.

You failed to hit esc so it inserted :wq as additional text. You then collected yourself, tried esc : w q one more time, and that worked.

Fire up vim one more time, opening the file as before.

  • Hit capital G to go to end of document.
  • With the cursor in the wayward :wq cline, hit "dd" lower case.
  • you shouldn't need to hit esc but do it anyway. It may beep.
  • now hit :wq

You must log in to answer this question.

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