Author Topic: Problem with this script?  (Read 3866 times)

gameking66 (OP)

  • Posts: 25
Problem with this script?
« on: March 19, 2010, 02:58:26 am »
I'm writing a simple terminal input script for Dingux that I call Terminoo. The script runs fine but it seems to simply freeze with no input or output whatsoever (but no syntax errors). I'm new to Linux bash scripting so I'm not particularly sure what the problem is, so I could use some help. My script is as follows:

Code: [Select]
#!/bin/sh
# Terminoo r3 - Terminal input for the Dingux via Dpad.
# Controls:
# Up - Confirm Letter
# Down - Erase Letter. If no letters left will recall last command if available.
# Left - Scroll backwards through alphabet. Symbols not yet implemeted.
# Right - Scroll forwards through alphabet. Symbols not yet implemeted.
# Start - Confirm command. Also saves command for recall.
# Select - Exit to launcher.
# Features:
# Saves last command.
# Able to execute bash commands on the fly from the Dingoo.
# To Do:
# Implement symbol input.
# Proper implementation of letter input.
# Use of A,B,X,Y buttons.
# Credits:
# Coded by n4ru (c) 2010

export SDL_NOMOUSE=1

resetVariables()
{
inputletter="A"
inputnumber="1"
string=""
stringlen="0"
}

setVars()
{
if [ "$inputnumber" = "0" ]
then inputnumber="26"
fi
if [ "$inputnumber" = "27" ]
then inputnumber="1"
fi
if [ "$inputnumber" = "1" ]
then inputletter="A"
fi
if [ "$inputnumber" = "2" ]
then inputletter="B"
fi
if [ "$inputnumber" = "3" ]
then inputletter="C"
fi
if [ "$inputnumber" = "4" ]
then inputletter="D"
fi
if [ "$inputnumber" = "5" ]
then inputletter="E"
fi
if [ "$inputnumber" = "6" ]
then inputletter="F"
fi
if [ "$inputnumber" = "7" ]
then inputletter="G"
fi
if [ "$inputnumber" = "8" ]
then inputletter="H"
fi
if [ "$inputnumber" = "9" ]
then inputletter="I"
fi
if [ "$inputnumber" = "10" ]
then inputletter="J"
fi
if [ "$inputnumber" = "11" ]
then inputletter="K"
fi
if [ "$inputnumber" = "12" ]
then inputletter="L"
fi
if [ "$inputnumber" = "13" ]
then inputletter="M"
fi
if [ "$inputnumber" = "14" ]
then inputletter="N"
fi
if [ "$inputnumber" = "15" ]
then inputletter="O"
fi
if [ "$inputnumber" = "16" ]
then inputletter="P"
fi
if [ "$inputnumber" = "17" ]
then inputletter="Q"
fi
if [ "$inputnumber" = "18" ]
then inputletter="R"
fi
if [ "$inputnumber" = "19" ]
then inputletter="S"
fi
if [ "$inputnumber" = "20" ]
then inputletter="T"
fi
if [ "$inputnumber" = "21" ]
then inputletter="U"
fi
if [ "$inputnumber" = "22" ]
then inputletter="V"
fi
if [ "$inputnumber" = "23" ]
then inputletter="W"
fi
if [ "$inputnumber" = "24" ]
then inputletter="X"
fi
if [ "$inputnumber" = "25" ]
then inputletter="Y"
fi
if [ "$inputnumber" = "26" ]
then inputletter="Z"
fi
}

terminalEntry()
{
read -s -n 3 -p "CMD $string$inputletter" change
if [ "$change" = "" ]
then
((inputnumber++))
setVars
fi
if [ "$change" = "" ]
then
((inputnumber--))
setVars
fi
if [ "$change" = "" ]
then
((stringlen++))
string = "$string$inputletter"
inputletter="A"
inputnumber="1"
fi
if [ "$change" = "" ]
then
if [ "stringlastactive" = "1" && "$stringlen" = "0"]
then
string="$stringlast"
stringlen="$stringlenlast"
else
((stringlen--))
string="${string%?}"
fi
inputletter="A"
inputnumber="1"
fi
if "$change"=="["
then
exit
else
$string
resetVariables
stringlenlast="$stringlen"
stringlast="$string"
stringlastactive="1"
fi
terminalEntry
}
« Last Edit: March 19, 2010, 03:01:58 am by gameking66 »

madcat1990

  • Guest
Re: Problem with this script?
« Reply #1 on: March 19, 2010, 02:51:57 pm »
All I see are functions, do you execute them in the script? Or put them on a loop?

show us the whole bash script if you hid some parts =)

gameking66 (OP)

  • Posts: 25
Re: Problem with this script?
« Reply #2 on: March 20, 2010, 02:34:37 am »
I'm assuming that was my problem then. For some strange reason I assumed it would execute the functions in the order they arrive, but that was pretty stupid of me. Would renaming terminalEntry to main in all instances work?

gameking66 (OP)

  • Posts: 25
Re: Problem with this script?
« Reply #3 on: March 20, 2010, 02:59:39 am »
Alright, now with this script I'm getting the error "Line 152: == not found". Line 152 contains nothing.

Code: [Select]
#!/bin/sh
export SDL_NOMOUSE=1
# Terminoo r4 - Terminal input for the Dingux via Dpad.
# Controls:
# Up - Confirm Letter
# Down - Erase Letter. If no letters left will recall last command if available.
# Left - Scroll backwards through alphabet. Symbols not yet implemeted.
# Right - Scroll forwards through alphabet. Symbols not yet implemeted.
# Start - Confirm command. Also saves command for recall.
# Select - Exit to launcher.
# Features:
# Saves last command.
# Able to execute bash commands on the fly from the Dingoo.
# To Do:
# Implement symbol input.
# Proper implementation of letter input.
# Use of A,B,X,Y buttons.
# Credits:
# Coded by n4ru (c) 2010

resetVariables()
{
inputletter="A"
inputnumber="1"
string=""
stringlen="0"
}

setVars()
{
if [ "$inputnumber" = "0" ]
then inputnumber="26"
fi
if [ "$inputnumber" = "27" ]
then inputnumber="1"
fi
if [ "$inputnumber" = "1" ]
then inputletter="A"
fi
if [ "$inputnumber" = "2" ]
then inputletter="B"
fi
if [ "$inputnumber" = "3" ]
then inputletter="C"
fi
if [ "$inputnumber" = "4" ]
then inputletter="D"
fi
if [ "$inputnumber" = "5" ]
then inputletter="E"
fi
if [ "$inputnumber" = "6" ]
then inputletter="F"
fi
if [ "$inputnumber" = "7" ]
then inputletter="G"
fi
if [ "$inputnumber" = "8" ]
then inputletter="H"
fi
if [ "$inputnumber" = "9" ]
then inputletter="I"
fi
if [ "$inputnumber" = "10" ]
then inputletter="J"
fi
if [ "$inputnumber" = "11" ]
then inputletter="K"
fi
if [ "$inputnumber" = "12" ]
then inputletter="L"
fi
if [ "$inputnumber" = "13" ]
then inputletter="M"
fi
if [ "$inputnumber" = "14" ]
then inputletter="N"
fi
if [ "$inputnumber" = "15" ]
then inputletter="O"
fi
if [ "$inputnumber" = "16" ]
then inputletter="P"
fi
if [ "$inputnumber" = "17" ]
then inputletter="Q"
fi
if [ "$inputnumber" = "18" ]
then inputletter="R"
fi
if [ "$inputnumber" = "19" ]
then inputletter="S"
fi
if [ "$inputnumber" = "20" ]
then inputletter="T"
fi
if [ "$inputnumber" = "21" ]
then inputletter="U"
fi
if [ "$inputnumber" = "22" ]
then inputletter="V"
fi
if [ "$inputnumber" = "23" ]
then inputletter="W"
fi
if [ "$inputnumber" = "24" ]
then inputletter="X"
fi
if [ "$inputnumber" = "25" ]
then inputletter="Y"
fi
if [ "$inputnumber" = "26" ]
then inputletter="Z"
fi
}

terminalEntry()
{
read -s -n 3 -p "CMD $string$inputletter" change
if [ "$change" = "" ]
then
inputnumber=$((inputnumber-1))
setVars
fi
if [ "$change" = "" ]
then
inputnumber=$((inputnumber-1))
setVars
fi
if [ "$change" = "" ]
then
stringlen=$((stringlen+1))
string = "$string$inputletter"
inputletter="A"
inputnumber="1"
fi
if [ "$change" = "" ]
then
if [ "stringlastactive" = "1" && "$stringlen" = "0"]
then
string="$stringlast"
stringlen="$stringlenlast"
else
stringlen=$((stringlen-1))
string="${string%?}"
fi
inputletter="A"
inputnumber="1"
fi
if "$change"=="["
then
exit
else
$string
resetVariables
stringlenlast="$stringlen"
stringlast="$string"
stringlastactive="1"
fi
terminalEntry
}


resetVariables
while [ "1" = "1" ]
do
terminalEntry
done

darfgarf

  • Guest
Re: Problem with this script?
« Reply #4 on: March 20, 2010, 08:49:46 am »
did you write it in windows? if so there could be extra windows end line characters in it, which it won't like

madcat1990

  • Guest
Re: Problem with this script?
« Reply #5 on: March 21, 2010, 01:18:41 am »
Alright, now with this script I'm getting the error "Line 152: == not found". Line 152 contains nothing.

paste 5 lines before 152 and 5 lines after, please

gameking66 (OP)

  • Posts: 25
Re: Problem with this script?
« Reply #6 on: March 21, 2010, 03:04:02 am »
did you write it in windows? if so there could be extra windows end line characters in it, which it won't like

I used Notepad++ which doesn't include any extra characters.

Alright, now with this script I'm getting the error "Line 152: == not found". Line 152 contains nothing.

paste 5 lines before 152 and 5 lines after, please

I pasted the entire script above, but the lines are:

Code: [Select]
resetVariables
while [ "1" = "1" ]
do
terminalEntry
done

There's nothing after.

madcat1990

  • Guest
Re: Problem with this script?
« Reply #7 on: March 22, 2010, 09:49:27 pm »
in this line:

Code: [Select]
while [ "1" = "1" ]
you are saying that 1's value is 1

it should be something like this:

Code: [Select]
while [ "1" ==  "1" ]
or even simpler:

Code: [Select]
while (true)

gameking66 (OP)

  • Posts: 25
Re: Problem with this script?
« Reply #8 on: March 23, 2010, 12:56:45 am »
in this line:

Code: [Select]
while [ "1" = "1" ]
you are saying that 1's value is 1

it should be something like this:

Code: [Select]
while [ "1" ==  "1" ]
or even simpler:

Code: [Select]
while (true)

I changed it to while (true) and I'm still getting "Line 152: == not found".

schanall

  • Posts: 139
Re: Problem with this script?
« Reply #9 on: March 23, 2010, 11:25:46 am »
It's easier to locate the error when you do it step by step. First of all delete all functions. Then paste one by one back again.

madcat1990

  • Guest
Re: Problem with this script?
« Reply #10 on: March 27, 2010, 05:29:04 am »
can you pm me this script so that I can take a closer look at it?

gameking66 (OP)

  • Posts: 25
Re: Problem with this script?
« Reply #11 on: March 30, 2010, 06:15:31 am »
can you pm me this script so that I can take a closer look at it?

The entire script is found in this post.