Results 1 to 4 of 4
  1. #1
    Join Date
    Sep 2009
    Posts
    16

    Unanswered: Error in IF Condtion .. Need Help!

    what is the syntax error in this
    Code:
    if [[ ${CYC_DT} -ge ${cur_sys_dt}]]; then
      echo "cycle date is equal"
    else
      echo "not equal"
    fi
    t.ksh[120]: Syntax error at line 283 : `then' is not expected.

    Thanks

  2. #2
    Join Date
    Jun 2003
    Location
    Toronto, Canada
    Posts
    5,516
    Provided Answers: 1
    That depends on the contents of the two variables. You may also want to insert a space before "]]".
    ---
    "It does not work" is not a valid problem statement.

  3. #3
    Join Date
    Jun 2007
    Location
    London
    Posts
    2,527
    I believe I've fixed most of the syntax errors below. You are also testing to see if $CYC_DT is greater or equal to $cur_sys_dt but then reporting that it is just equal, use -eq if you want to test equality between numbers. Also if either of these variables don't have a value then you'll get a syntax error. Otherwise it's fine
    Code:
    if [ $CYC_DT -ge $cur_sys_dt ]
    then
       echo "cycle date is equal"
    else
       echo "not equal"
    fi
    Last edited by mike_bike_kite; 10-31-09 at 14:56.

  4. #4
    Join Date
    Jan 2007
    Location
    Jena, Germany
    Posts
    2,721
    I always enclose variables in conditions double-quotes to avoid semantic changes, depending on the variable content. (For SQL, you would say to avoid SQL injection.)
    Code:
    if [ "$CYC_DT" -ge "$cur_sys_dt" ]
    Knut Stolze
    IBM DB2 Analytics Accelerator
    IBM Germany Research & Development

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •