Results 1 to 2 of 2
  1. #1
    Join Date
    Jul 2011
    Posts
    4

    Unanswered: Assign zero to the existing variable

    Hi, I have a variable which read the value from the lines, and if it is empty string (5 bytes), then I have to assign this variable to zero "0", it able to detect the data is empty by showing me the message "empty", but not able to assign it as zero.

    WTHP=`echo "$file" | cut -c158-162`

    if [[ $WTHP = " " ]]
    then
    echo "empty" >> $Log
    $WTHP = 0
    echo "$WTHP=" $WTHP >> $Log
    fi

    it will show me error message "not found".
    I have tried to code it as below:
    1) WTHP = 0
    OR
    2) WTHP = [0]
    OR
    3) WTHP = "0"
    OR
    4) WTHP_1 = 0, then echo this variable, but still will failed to assign zero to this variable and show me same error message

    Please advise.

  2. #2
    Join Date
    Sep 2009
    Location
    Ontario
    Posts
    1,057
    Provided Answers: 1
    Do not use spaces around the = sign when assigning a value.
    Code:
    WTHP=0
    if [ $WTHP -eq 0 ]
    then
         echo WTHP is the number zero
    fi
    WTHP="0"
    if [ "$WTHP" = "0" ]
    then
        echo WTHP is the letter zero
    fi

Posting Permissions

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