-1

I have the following script in my spec file %preun tag:

if [ $1 -eq 0 ]; then 
echo "Stopping blah service before uninstalling.." 
. /etc/init.d/blahforever stop 
echo "blah service stopped."
fi

I get "syntax error near unexpected token `fi'" error

but when I add else block it runs fine:

if [ $1 -eq 0 ]; then 
    echo "Stopping blah service before uninstalling.." 
    . /etc/init.d/blahforever stop 
    echo "blah service stopped."
else
    echo "I dont need else block"
fi

But I don't need an else block! How do I get rid of it? PS: I tried removing the semi colon after the condition and still didn't help.

nolimit
  • 814
  • 10
  • 19
  • That looks like it points to an error in /etc/init.d/blahforever – glenn jackman Apr 01 '15 at 19:05
  • You also appear to have indented the script some in that change (and who knows what else). If you remove those two else/echo lines from the bottom snippet do you still get that syntax error? (Also why dot-source the service script invocation?) – Etan Reisner Apr 01 '15 at 19:05
  • Yes I did try removing all echo lines and still fails. And the script works as I said if I just remove the else block it will work. – nolimit Apr 01 '15 at 21:19
  • @EtanReisner removing indentation seems to work! – nolimit Apr 02 '15 at 18:47
  • What do you mean "removing indentation seems to work"? That doesn't make sense. Can you paste the **exact** lines in your scriptlet? – Etan Reisner Apr 02 '15 at 19:05

1 Answers1

0

This is a shell syntax error in the line ". /etc/init.d/blahforever stop".

There is no file to be sourced (i.e. read into the current shell) called "stop".

Jeff Johnson
  • 2,310
  • 13
  • 23