On Mon, 8 May 2000, Minh Van wrote:

> 
> what's the difference between elif & else in shell scripts ? they seem the
> same to me.

else says to do something if the if condition was false. elif allows
you to test for another condition which might be completly unrelated
to the first condition. Consider the following pieces of
code with identical behaviour

    if some condition is true
    then
        act on that condition
    elif some other condition is true
    then
        act on the other condition
    elif yet another condition is true
    then
        act on the third condition
    else
        do something if none of the above were true
    fi

    if some condition is true
    then
        act on that condition
    else
        if some other condition is true
        then
            act on the other condition
        else
            if yet another condition is true
            then
                act on the third condition
            else
                do something if none of the above were true
            fi
        fi
    fi

Usage of either method is a matter of your own personal coding style.
I used to favour method 2 but I'm gradually moving towards using
elif.

Regards
Peter
----------
Peter Samuel                                [EMAIL PROTECTED]
Technical Consultant                        or at present:
eServ. Pty Ltd                              [EMAIL PROTECTED]
Phone: +61 2 9206 3410                      Fax: +61 2 9281 1301

"If you kill all your unhappy customers, you'll only have happy ones left"

--
SLUG - Sydney Linux Users Group Mailing List - http://www.slug.org.au
To unsubscribe send email to [EMAIL PROTECTED] with
unsubscribe in the text

Reply via email to