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?

Answers


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" ]

Need Your Help

Silverlight Control Lifecycle

silverlight-3.0

Could anyone tell me the events that are fired during a Silverlight control's lifecycle please?

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.