AIX

AIX

Connect with fellow AIX users and experts to gain knowledge, share insights, and solve problems.


#Power
 View Only
  • 1.  korn shell- if statement

    Posted Mon June 30, 2008 02:03 PM

    Originally posted by: SystemAdmin


    Hi,

    I am kind of confused with using if statement in korn shell scripting...which of the following is correct

    if ; then
    do the work
    esle
    exit
    fi

    or

    if condition ; then
    do the work
    else
    exit
    fi

    When do we use to braces and when we do not?
    also is ; after the braces a must? I have scripts which the if statement works without the ";" before "then"
    #AIX-Forum


  • 2.  Re: korn shell- if statement

    Posted Mon June 30, 2008 02:09 PM

    Originally posted by: SystemAdmin


    ooops when I posted the message is not showing my braces.
    
    
    
    if [ 
    condition ] ; then
    do the work
    else exit
    fi

    or
    
    
    
    if 
    contion ; then
    do the work
    else exit
    fi

    do I need two braces or one? and also when ; is needed and when it is not needed.
    #AIX-Forum


  • 3.  Re: korn shell- if statement

    Posted Wed July 02, 2008 10:37 AM

    Originally posted by: SystemAdmin


    breez wrote:
    ooops when I posted the message is not showing my braces.
    <pre class="jive-pre"><code class="jive-code jive-java">if ; then
    do the work
    else exit
    fi
    </code></pre>
    or
    <pre class="jive-pre"><code class="jive-code jive-java">if contion ; then
    do the work
    else exit
    fi
    </code></pre>
    do I need two braces or one? and also when ; is needed and when it is not needed.

    I ALWAYS use 2 braces.

    The semi colon IS required if you are putting 2 keywords on the same line

    if x=1;then echo "hello"; else exit;fi

    Is the same as:

    if x=1
    then echo hello
    else exit
    fi
    #AIX-Forum