amanada.williams
amanada.williams

Reputation: 477

syntax check. group two if statements

if [ $DISTRO = "REDHAT"] || [ $DISTRO = "FEDORA"]; then 
    if ! rpm -qa | grep -q glibc-static; then
        $BIN_ECHO -e " Package [glibc-static] not found. Installing.. "
        yum install glibc-static
    elif
        $BIN_ECHO -e " All required packages installed.. "
    fi
elif [ $DISTRO = "DEBIAN"]; then 
    if ! dpkg-query -l glibc; then
        $BIN_ECHO -e " Package [glibc] not found. Installing.. "
        apt-get install glibc
    elif
        $BIN_ECHO -e " All required packages installed.. "
    fi
fi

line 156: syntax error near unexpected token `fi'

How do I put the two statements together?

Upvotes: 1

Views: 103

Answers (1)

William Pursell
William Pursell

Reputation: 212404

You must have a space before the final ] on each test.

For example:

if [ $DISTRO = "REDHAT"] || [ $DISTRO = "FEDORA"]; then

must be re-written as either:

 if [ "$DISTRO" = REDHAT ] || [ "$DISTRO" = FEDORA ]; then

or

if test "$DISTRO" = REDHAT || test "$DISTRO" = FEDORA; then

Also note that there is no reason to quote literal strings, but you should quote variables.

You can also do :

if test "$DISTRO" = REDHAT -o "$DISTRO" = FEDORA; then

or

case "$DISTRO" in
REDHAT|FEDORA) ... ;;
DEBIAN) ... ;;
esac

Upvotes: 4

Related Questions