line 63: syntax error near unexpected token `;' in bashrc

1

1

I have bash function of:

myworkhomebrewapp(){ atom $HOMEBREW_FRONTEND; atom $HOMEBREW_BACKEND; workon homebrew_server; cd $HOMEBREW_BACKEND; python manage.py runserver & ; /usr/bin/open -a "/Applications/Google Chrome.app" "file:///Users/cchilders/projects/good_brews/frontend/index.html" ;}

But it causes error

$ src
-bash: /Users/cchilders/.bash_profile: line 63: syntax error near unexpected token `;'
-bash: /Users/cchilders/.bash_profile: line 63: `myworkhomebrewapp(){ atom $HOMEBREW_FRONTEND; atom $HOMEBREW_BACKEND; workon homebrew_server; cd $HOMEBREW_BACKEND; python manage.py runserver & ; /usr/bin/open -a "/Applications/Google Chrome.app" "file:///Users/cchilders/projects/good_brews/frontend/index.html" ;}'

I don't know what causes error, but commenting that line out fixes it. Where is my bash function broken please? Thank you

One solution:

I was able to fix the issue by splitting new lines in my .bashrc, which isn't what I wanted:

myworkhomebrewapp(){
    atom $HOMEBREW_FRONTEND
    atom $HOMEBREW_BACKEND
    workon homebrew_server
    cd $HOMEBREW_BACKEND
    python manage.py runserver &
    sleep 5
    /usr/bin/open -a "/Applications/Google Chrome.app" "file://$HOMEBREW_FRONTEND/index.html"
}

codyc4321

Posted 2016-12-15T00:42:30.197

Reputation: 298

2It's the semicolon after the ampersand that is causing the error (pity that bash doesn't report the column as well as the line number): blank statements are not allowed. You can separate statements by either ; or & (as well as other separators), but not both. Just typing ; into bash gives the same error. – AFH – 2016-12-15T01:07:55.403

Answers

2

syntax error near unexpected token ;

Running your one liner through ShellCheck throws up the following warning/errors (warnings are green, errors are red):

enter image description here

Removing the ; from python manage.py runserver & ; removes the error, leaving just the warnings:

enter image description here


ShellCheck - A shell script static analysis tool

ShellCheck is a GPLv3 tool that gives warnings and suggestions for bash/sh shell scripts:

Screenshot of a terminal showing problematic shell script lines highlighted.

enter image description here

The goals of ShellCheck are

  • To point out and clarify typical beginner's syntax issues that cause a shell to give cryptic error messages.

  • To point out and clarify typical intermediate level semantic problems that cause a shell to behave strangely and counter-intuitively.

  • To point out subtle caveats, corner cases and pitfalls that may cause an advanced user's otherwise working script to fail under future circumstances.

Source ShellCheck

DavidPostill

Posted 2016-12-15T00:42:30.197

Reputation: 118 938

Crossed with you yet again! Thanks for the site - I didn't know about it. – AFH – 2016-12-15T01:12:24.363

@afh Hehe. If it wasn't for that site I wouldn't have been able to answer the question - I'm no bash expert :) – DavidPostill – 2016-12-15T01:14:58.447

I found it by replacing each ; with && in turn. When the error report changed to && I then knew which semicolon was at fault. – AFH – 2016-12-15T01:19:01.687

@afh Oh, that's a nice debugging technique. – DavidPostill – 2016-12-15T01:20:12.320