jmkgreen
jmkgreen

Reputation: 1643

Syntax error: "}" unexpected (expecting "fi")

Here's a simple shell script downloaded from Atlassian and slightly adjusted to meet all suggestions found so far:

#!/bin/sh

# RUN_AS: The user to run fisheye as. Its recommended that you create a separate user account for security reasons
RUN_AS=fisheye

# FISHEYE_HOME: The path to the FishEye installation. Its recommended to create a symbolic link to the latest version so
# the process will still work after upgrades.
FISHEYE_HOME="/opt/atlassian/fisheye"

fisheyectl() {
        ARGS="--Xdisable-tags --Xenable-git-content-hash-resolving-heuristic"
        CMD="$FISHEYE_HOME/bin/fisheyectl.sh $1"
        if [ $1 == "run" ]
        then
            CMD="nohup $CMD $ARGS >> $FISHEYE_HOME/var/log/nohup.out &";
        fi
        if [ "$USER" != "$RUN_AS" ]
        then
                su - "$RUN_AS" -c "$CMD";
        else
                sh -c "$CMD";
        fi
}

case "$1" in
        start)
                fisheyectl run
                ;;
        stop)
                fisheyectl stop
                ;;
        restart)
                fisheyectl stop
                sleep 10
                fisheyectl run
                ;;
        *)
                echo "Usage: $0 {start|stop|restart}"
esac

exit 0

I have run this through dos2unix locally. On executing:

fisheye: 23: fisheye: Syntax error: "}" unexpected (expecting "fi")

Any suggestions?

Upvotes: 0

Views: 3732

Answers (3)

pascal
pascal

Reputation: 21

I had a similar problem and it turned out I had to change the #/bin/sh line into #/bin/bash

Upvotes: 2

Keith Thompson
Keith Thompson

Reputation: 263517

Change this:

if [ $1 == "run" ]

to this:

if [ "$1" = "run" ]

In bash's built-in [ command, == is a synonym for =, but not all implementations of the [ (test) command recognize ==. = is the original operator for string equality comparison -- and your script has #!/bin/sh, which may or may not be bash-compatible.

I've also added double quotes around $1. They're not strictly necessary in this case, since you always call fisheyectl() with a single word argument, but it's a good idea in general to enclose variable references in single quotes. (Without the quotes, if you called fisheyectl() with no arguments, you'd have if [ = "run" ], which is a syntax error.)

Upvotes: 0

michael501
michael501

Reputation: 1482

Change

if [ $1 == "run" ]

to

if [ ${1:-X} = "run" ]

Upvotes: 0

Related Questions