You are not logged in.

#1 2013-01-31 13:22:55

ThunderRush
Member
From: Austria
Registered: 2013-01-31
Posts: 22

Bash Script with a Syntax Error

I have a short question, and I'm breaking my - my probably stupid - head over it.

#!/bin/bash

if [ "$1" = "-p" ]
then
        echo -e "Doing a Pacman-Update with \e[0;31mStandard\e[00m settings."
        pacman -Suyy
elif [ "$1" = "-y" ]
        if [ "$2" = "-s" ]
        then
                echo -e "Doing a Yaourt-Update \e[0;31mwithout asking\e[00m!"
                yaourt -Suyy --aur --noconfirm
        else
                echo -e "Doing a Yaourt-Update \e[0;31mwith asking\e[00m!"
                yaourt -Suyy --aur
        fi
#else
#       echo -e "Please specify the correct options! packages [-p] [-y] [-s]"
fi

Returns...

My lovely bash wrote:

/scripts/packages: Zeile 18: Syntaxfehler beim unerwarteten Wort (Syntaxerror at unexpected word) `fi'
/scripts/packages: Zeile 18: `fi

Why is fi and unexpected word? It closes my first if. Does not work with the else either, then it says that else is unexpected.
I hope bash does not expect a bush of flowers and a goldring from me.

Last edited by ThunderRush (2013-01-31 13:26:18)

Offline

#2 2013-01-31 13:28:59

portix
Member
Registered: 2009-01-13
Posts: 755

Re: Bash Script with a Syntax Error

bash expects a then after elif.

Offline

#3 2013-01-31 13:29:23

gridcol
Member
From: Karlsruhe, Germany
Registered: 2012-03-27
Posts: 32

Re: Bash Script with a Syntax Error

Try to put a second "then" after your line with the elif. Should work fine then.

Last edited by gridcol (2013-01-31 13:30:00)

Offline

#4 2013-01-31 16:25:55

ThunderRush
Member
From: Austria
Registered: 2013-01-31
Posts: 22

Re: Bash Script with a Syntax Error

Thank you two guys a lot. I asked someone who was supposed to know such stuff, but he said that I don't need a than after elif.
Thanks again.

Offline

Board footer

Powered by FluxBB