t3hcakeman
t3hcakeman

Reputation: 2339

Syntax error near unexpected token "elif" in bash

Here's my code to display some dialogs.

#!/bin/bash
output=$(zenity  --list --text="Choose action" --column= --hide-header "Hidden Files" "Desktop")
if [ $output = "Hidden Files"]
    then
        output2=$(zenity  --list --text="Do what?" --column= --hide-header "Show" "Hide")
        if [ $output2 = "Show"]
            then
                echo showing files
            else
                echo hiding files
elif [ $output = "Desktop"];then
        output3=$(zenity  --list --text="Do what?" --column= --hide-header "Show" "Hide")
        if [ $output2 = "Show"]
            then
                echo showing files
            else
                echo hiding files
    else
        exit
fi

I get this error after the first dialog:

systool.sh: line 12: syntax error near unexpected token `elif'
systool.sh: line 12: `elif [ $output = "Desktop"];then'

Whats wrong?

Upvotes: 0

Views: 7144

Answers (3)

Aaron Digulla
Aaron Digulla

Reputation: 328624

You're missing a fi after both echo hiding files

Upvotes: 0

dogbane
dogbane

Reputation: 274632

You need to close both of your inner if-else statements with a fi.

For example:

    if [ $output2 = "Show"]
        then
            echo showing files
        else
            echo hiding files
    fi

You also need a space before the closing ] in your if conditions. For example:

    if [ $output2 = "Show" ]

Upvotes: 4

Michael Krelin - hacker
Michael Krelin - hacker

Reputation: 143099

Your inner ifs have no corresponding fis.

Upvotes: 0

Related Questions