ksh scripting-difference between { and (

Posted on 2005-04-11
Last Modified: 2013-12-27
i asked a question earlier and was given a great solution and here is the command:
status=$(egrep -c -i 'fail' /home/mtsadmin/GABS_trades_EUR_bcp.out)

now i want to understand the use of paranthesis vs squiggly brackets '{}'?
and what is the $ doing in this case?

thanks to all
Question by:pdadddino

    Author Comment

    if (($status == 0))

    same for this command. what do double parenthesis mean?
    LVL 1

    Accepted Solution


    (( .. )) are used in arithmetic expressions;
    ( .. ) are used to create subshells.

     ( list )
                  Execute list in a subshell.  There is no implicit way to pass environment changes from  a  subshell
                  back to its parent.

     { list }
                  Compound construct; list is executed, but not in a subshell.  Note that { and } are reserved words,
                  not meta-characters.

    Please go through man ksh for more info..

    LVL 10

    Assisted Solution

    means that somecommand is executed and the output of that command is assigned to a variable called xx
    this is korn shell syntax. maybe you know the bourne shell syntax
    which does exactly the same and is also valid for kornshell.

    as for the {} let me do an example
    echo $flowers
    does not give you any output while
    echo ${flower}s
    gives you "roses" as output (echo $flower s would give you "rose s" which you would probably not want)

    finally the (( )), as described by kusuma are use to tell the korn shell that we are in aritmetics. This is often used for if-statements. let's make an example:

    $ if (( 2+2 == 4 ))
    > then
    > echo hello
    > fi

    $ if [[ 2+2 == 4 ]]
    > then
    > echo hallo
    > fi

    In the first example the condition is true, because we are in aritmethics. In the second example (square brackets) we are talking about text, which means the string "2+2" is compared to the string "4" which of course is not the same.


    Author Comment

    Thanks for taking the time. It certainly clears some things up!

    Featured Post

    What Should I Do With This Threat Intelligence?

    Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

    Join & Write a Comment

    Attention: This article will no longer be maintained. If you have any questions, please feel free to mail me. Please see for the updated article. It is avail…
    I promised to write further about my project, and here I am.  First, I needed to setup the Primary Server.  You can read how in this article: Setup FreeBSD Server with full HDD encryption (…
    Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:
    This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.

    730 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    15 Experts available now in Live!

    Get 1:1 Help Now