If then expressions with integers

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • garymcadam
    New Member
    • Aug 2007
    • 1

    If then expressions with integers

    I have written a script with a variable, but my test does not pick up decimals.
    if [ "$G62" -eq 0.0 ]
    then ......

    If $G2 is 0.01 the if statement regards it as 0 and the test is not true.
    How can I get my if statement to pick up decimals?
    Thanks
    Gary
  • coaxfiber
    New Member
    • Mar 2007
    • 60

    #2
    Originally posted by garymcadam
    I have written a script with a variable, but my test does not pick up decimals.
    if [ "$G62" -eq 0.0 ]
    then ......

    If $G2 is 0.01 the if statement regards it as 0 and the test is not true.
    How can I get my if statement to pick up decimals?
    Thanks
    Gary
    #!/bin/sh
    echo "Input: \c"
    read f
    if
    [ "$f" = '0.01' ]
    then
    echo "good"
    else
    echo "bad"
    fi

    Comment

    Working...