Results 1 to 6 of 6
  1. #1
    Join Date
    Feb 2005
    Posts
    11

    Unanswered: adding problem - korn shell

    Dear friends

    I have problem while adding a number. I am using korn shell. The code is

    week_number=`date +%W`
    day_add=$(($week_number+1))
    echo $day_add

    if week number 01-07 then it is adding, but if the week number is 08-09 then it says there is illegal operations. If i try to add 8+1 it is adding, if i include '0' then it says error.

    Please if any one knows this type of error. Please give me the reason for happening like that.

    Thank you

  2. #2
    Join Date
    Aug 2004
    Location
    Rome, Italy
    Posts
    81
    hi,
    i don't know what happened there by you but I tryed this script in UnixWare(SCO):

    #!/bin/ksh

    var=`date +%W`
    i=0
    while test $i -lt 5
    do
    var=$(($var+3))
    echo $var
    i=$i+1
    done

    and I had this result:

    11
    14
    17
    20
    23

    Just try what I wrote in a script apart. If it works, it means that there is something else in your script that doesn't work well.

    Bye,
    ducasio

  3. #3
    Join Date
    Jun 2003
    Location
    West Palm Beach, FL
    Posts
    2,713

    Cool

    Try:
    Code:
    ((day_add = week_number + 1))
    The person who says it can't be done should not interrupt the person doing it. -- Chinese proverb

  4. #4
    Join Date
    Jun 2003
    Location
    Toronto, Canada
    Posts
    5,516
    Provided Answers: 1
    Quote Originally Posted by unixshell
    if week number 01-07 then it is adding, but if the week number is 08-09 then it says there is illegal operations. If i try to add 8+1 it is adding, if i include '0' then it says error.
    I think that for the shell a leading zero indicates that it's dealing with an octal number, where the digit 8 is invalid. Try specifying the number base:
    Code:
    var=$((10#$var+3))

  5. #5
    Join Date
    Feb 2005
    Posts
    11

    adding problem - korn shell

    Thanks for your reply.

    But, this script runs in other unix server. i don't know, whethere any setup should be set or not in this server. I sloved the problem using expr. I don't know why isn't running, is there any setting?

    if u know kindly let me know.

    thanks for your interest to reply.

    bye

  6. #6
    Join Date
    Jan 2005
    Location
    Lyon,France
    Posts
    1
    Force week_number into integer
    typeset -i week_number=`date +%W`


Posting Permissions

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