Pepster K.
Pepster K.

Reputation: 349

How can I fix this bash if/then/else script?

What is wrong with my simple if/then/else bash script?

if [ "$C" = "dev" ];then
  export PREFIX=/home/bubu
  export SERVER=localhost:2112
elif [ "$C" = "test" ]
  export PREFIX=/server/node
  export SERVER=e.foo.com:44033
else
  export PREFIX=/server/node
  export SERVER=f.foo.com:44033
fi

./foo.sh: line 9: syntax error near unexpected token `else'
./foo.sh: line 9: `else'

Upvotes: 1

Views: 1831

Answers (3)

William Pursell
William Pursell

Reputation: 212288

I would suggest fixing it with a case statement:

case "$C" in
  dev) export PREFIX=/home/bubu SERVER=localhost:2112;;
  test) export PREFIX=/server/node SERVER=e.foo.com:44033;;
  *) export PREFIX=/server/node SERVER=f.foo.com:44033;;
esac

Upvotes: 2

cucurbit
cucurbit

Reputation: 1442

A "then" is missing after elif statement:

elif [ "$C" = "test" ]; then

Upvotes: 0

jmajnert
jmajnert

Reputation: 418

Should be:

elif [ "$C" = "test" ]; then

Upvotes: 4

Related Questions