Link to home
Start Free TrialLog in
Avatar of Bruce Gust
Bruce GustFlag for United States of America

asked on

Unexpected "then" in shell script. How do I fix it?

Here's my error:

bsmart_1  | ./bin/start.sh: 9: ./bin/start.sh: Syntax error: "fi" unexpected (expecting "then")

Here's the code:

#!/usr/bin/env bash

if [ "$NODE_ENV" = "production" ]; then
    node index.js
else
    ./bin/create-test-user
    ./bin/create-f5500
    nodemon index.js --legacy-watch --ext js,mjs,json,twig
fi

No experience at all with shell scripts, so I'm not even sure where to begin.

What's wrong and how do I fix it?

Thanks!
SOLUTION
Avatar of Ryan Chong
Ryan Chong
Flag of Singapore image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Bruce Gust

ASKER

Morning, Ryan!

That would've been awesome, but it didn't work.

There may be more to this, however. Let me show you everything that I'm getting on my Command Line:

bsmart_1  | yarn run v1.19.1
bsmart_1  | $ sh ./bin/start.sh
: not found ./bin/start.sh: 2: ./bin/start.sh:
bsmart_1  | ./bin/start.sh: 10: ./bin/start.sh: Syntax error: "fi" unexpected (expecting "then")

bsmart_1  | error Command failed with exit code 2.
bsmart_1  | info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
bsmart_bsmart_1 exited with code 2
Stopping bsmart_mongo_1    ... done
Aborting on container exit...

Not sure if : not found ./bin/start.sh: 2: ./bin/start.sh: is relevant, but I wanted to be sure to include that in case that makes a difference.
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Gentlemen!

This problem has taken a little bit of a different turn.

The scripting isn't the problem, as that's not something I'm tasked with creating or fixing. The real problem is eliminating it from my Git index. Try as I might, it keeps surfacing as an "unadded' change, and then I get into permissions and it's a mess.

For the sake of courtesy, I'm going to wrap up this question, but if you would like to weigh in on what amounts to a Git issue, here's the question:

https://www.experts-exchange.com/questions/29180493/How-can-I-get-rid-of-this-file-that-I-don't-have-permissions-for.html#questionAdd

Thanks!