1

I have the following function in bash, who was previously in the case part of a switch, but no matter where I put it I always get a syntax error

    do_start(){
    if[f $PIDFILE]; then
    echo "supervisord already running: $PIDFILE" exit 1 
    fi
    log_begin_msg "Starting Supervisor daemon manager..."
    start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $SUPERVISORD -- $OPTS || log_end_msg 1
    log_end_msg 0
    }

and I get:

    runScript.sh: Syntax error: "then" unexpected (expecting "}")

I don't know what is going on please help

1 Answer 1

2

Spaces around [ and ] are needed and I think you meant -f to check if this is a file.

You need to replace:

if[f $PIDFILE];

by:

if [ -f "$PIDFILE" ];

OR better (since you're using BASH)

if [[ -f "$PIDFILE" ]];
Sign up to request clarification or add additional context in comments.

2 Comments

I can't believe that a space could do such damage, thank you!
Yes BASH/shell syntax is pretty rigid on use of spaces and quotes.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.