• Man of BASH!

    From Spectre@21:3/101 to Tenser on Monday, February 10, 2020 11:04:00
    Can you riddle me whats wrong with this?

    check () {
    if [ "$TEMP" == "v3.3:" ] || [ "$TEMP" == "" ]; then
    TEMP="firmware"
    sleep 5
    fi
    }

    Its not matching the v3.3: for some reason...

    Spec


    --- SuperBBS v1.17-3 (Eval)
    * Origin: < Scrawled in blood at The Lower Planes > (21:3/101)
  • From Spectre@21:3/101 to tenser on Monday, February 10, 2020 17:03:00
    Can you riddle me whats wrong with this?

    How are you invoking it? Seems to work ok on my machine:

    #!/bin/bash

    read () {
    TEMP="$(./temp | cut -d ' ' -f10)"
    TIME="$(date +%R)"
    }

    check () {
    if [ "$TEMP" == "v3.3:" ] || [ "$TEMP" == "" ]; then
    TEMP="firmware"
    sleep 5
    fi
    }


    TEMP="firmware"
    until [ $TEMP != "firmware" ]; do
    read
    echo $TIME $TEMP
    check
    done
    echo $TEMP $TIME
    echo "Frankston $TEMP at $TIME" > /bbs/ansi/local.tmp

    This is the rest of it, somehow v3.3: is making it into the output..

    Spec


    --- SuperBBS v1.17-3 (Eval)
    * Origin: < Scrawled in blood at The Lower Planes > (21:3/101)
  • From Spectre@21:3/101 to tenser on Tuesday, February 11, 2020 12:09:00
    read () { TEMP="$(./temp | cut -d ' ' -f10)"

    the script ./temp queries the thermometer and returns a string full of garbage aside from the temp. Failures show up as "firmware", "", or "v3.3:"

    Ah, I see the issue. Let's break this apart.

    A metapoint: the shell has a builtin command called `read` to read a

    Ok so we rename read to something else... so far so good...

    check () { if [ "$TEMP" == "v3.3:" ] || [ "$TEMP" == "" ]; then TEMP="firmware"

    Note here that you _assign_ $TEMP to the string "firmware" if your conditions match. So if `$TEMP` was "v3.3:" it becomes "firmware".

    Whats happening here is... firmware, v3.3: and "" are all failures, but I'm looping on firmware, so if it equals one of the other two, I change it "firmware" A successful result looks like 21.5c. This logic mostly works, at least it does for "" and firmware, I don't comprende why v3.3: is an exception.

    TEMP="firmware" until [ $TEMP != "firmware" ]; do

    This loop will not terminate while "$TEMP" == "firmware".

    As noted above, its only checking one status on the loop, so other failures need to be made into a logical failure. It does terminate quite nicely in normal use. To be honest, when I started this, firmware was the only issue
    I was looking for, then I discovered the possible results.

    Metanote: You're running an `until` loop on a negative equality
    while [ $TEMP == "firmware" ]; do

    Again when I started what I had made sense, to me, and I was having trouble wrapping my head around the while possibility.. however it really amounts to the same thing... at least logically.. and yes yours makes more sense :)

    check

    ...But here, you reassign $TEMP to "firmware", overwriting
    whatever $TEMP had been.
    So when you go around the loop again, $TEMP is "firmware"
    and the loop never terminates.

    Thats partially right, there are 3 failures, but success is something that doesn't match any known failure, so while it can look endless, it does exit on anything other than those values.

    echo "Frankston $TEMP at $TIME" > /bbs/ansi/local.tmp

    And these two lines are never executed. Note that the last
    line would truncate whatever had been in local.tmp, which
    may or may not be what you want.

    So long as the values mentioned above aren't met this does get executed, the file local.tmp is only the current time, temperature so overwriting is a good thing. Its not a log as such. I have that being done elsewhere.

    I might have to cut it out, and pore over it a bit more in a shell, but I'm not
    entirely with your rewrite.. :/

    Spec


    --- SuperBBS v1.17-3 (Eval)
    * Origin: < Scrawled in blood at The Lower Planes > (21:3/101)
  • From Spectre@21:3/101 to Spectre on Tuesday, February 11, 2020 16:58:00
    Maybe I ought to borrow BP's hand and smack my forehead with it a few times. I just found the problem with the detection string... case.... it is in fact V3.3: that arrives not v3.3: gah..

    Spec


    --- SuperBBS v1.17-3 (Eval)
    * Origin: < Scrawled in blood at The Lower Planes > (21:3/101)