Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

stty help please

Status
Not open for further replies.

hokky

Technical User
Nov 9, 2006
170
AU
Hi guys,

Can you please help me modify my script, I know I'm pretty close but I need someone help to nail it

Here's my code :
Code:
readkey() {
    oldstty=`stty -g`
    stty -icanon -echo min 0 time 100
    dd bs=1 count=1 <&0 2>/dev/null
    stty $oldstty
}

process() {
    mychar=
    mystring=
    flag="true"

    echo "$START_INPUT\c"

    while true
    do
        mychar=$(readkey)

        if [[ -z $mychar ]];then
                break
        fi

        if [[ "$mychar" = "^?" ]];then
                if [[ ${#mystring} -gt 0 ]];then
                        tput cub1 ; echo " \c" ; tput cub1
                        mystring="${mystring%?}"
                fi
        elif [font color=red][[ "$mychar" == "^M" ]][/font];then
                flag="false"
                echo "flag $flag\c"
                break
        else
                echo "$mychar\c"
                mystring="$mystring"$mychar

        fi

    done

    echo $flag

    SEL=$mystring
    echo "$END_INPUT\c"

    if [[ "$flag" == "true" ]];then
        timeout
    fi

}
As you can see the red one, I'm trying to change the $flag value if enter is pressed.

But the fact is the $flag always true

Thanks guys
 
Sorry wrong tags,

Here's the red one:
<font color="red">[[ "$mychar" == "^M" ]]</font>

 
Hi

Abit tricky that red...

What shell you use ? A suppose it is [tt]ksh[/tt]. But if is [tt]bash[/tt], I would prefer the red part this way :
Code:
[[ "$mychar" == $'\0D' ]]
By the way, better give up and read TGML to find out that the correct code is [tt][ignore][red][/ignore][/tt] .. [tt][ignore][/red][/ignore][/tt] or [tt][ignore][/ignore][/tt] .. [tt][ignore][/ignore][/tt].

Feherke.
 
yes feherke,

It's ksh.

Your way doesn't work in ksh.

Thanks about your advice about tags, I thought it's HTML
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top