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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

trouble with controlling loop in script and debugging 5

Status
Not open for further replies.

ZiggyS1

Programmer
Oct 6, 2008
97
CA
hi,

I'm having a few problems, I am adapting this script in baby steps, and learning as I go.

Right now I have it collecting scans and writing (appending) to a file. What I wanted to do was have a user scan/enter an order number and then all subsequent scans would write to the file with the order number and UPC beside...

ORD1 772454051111
ORD1 772454050855
ORD1 883049178936
ORD1 883049128115

the problem is after each scan I want it to hold onto the order # and stay on the barcode field... so I don't lose the Order Variable.


I was trying to debug with a counter, but could not get my IF condition to work... just need a little guidance to get me in the right direction.

I know there is a lot missing from the code to make it better, but I am only focusing on this portion at the moment.


Code:
#!/bin/sh
#--------------------------------------------
# Author: Ziggy 


# Date  : January 18 2011 
# RF scanning 
#--------------------------------------------

# Main Variables Definition

LOGO="RF Scan Menu"
bold=`tput smso`
offbold=`tput rmso`
counter=1

#------------------------------------------------------
# MAIN MENU PROMPTS
#------------------------------------------------------
amenu="Type exit to close";


#------------------------------------------------------
#  MAIN Routine
#------------------------------------------------------

# trying to use to debug and count loop... gives error for...bracket  }
#% if ($counter > 1 ) {
#% break
#% }

mainframe () {
clear
tput cup   3 1; echo xxxxxxxxxxxxxxxxxxxxx 
tput cup   4 1; echo x; tput cup 4 21; echo x
tput cup   5 1; echo xxxxxxxxxxxxxxxxxxxxx
tput cup   9 5; echo Scan Barcode
}

themenu () {
tput cup  0 4; echo "${bold} Company Name ${offbold}"
tput cup  1 5; echo "${bold} $LOGO ${offbold}\n"
tput cup  4 2; echo $amenu; 
tput cup  9 0; echo $MSG

# position of field to scan into

tput cup  8 3; echo "Order: "
tput cup  10 2; echo "Scan: "

  tput cup 8 10; read ORDN
  
}

 
#------------------------------------------------------
# MAIN LOGIC
#------------------------------------------------------

#MSG=
while  true
do
  mainframe
  themenu
  tput cup 10 10; read answer

#  MSG=
  case $answer in

       exit) clear;break;;
    
	  *)echo $ORDN $answer >> /home/zigsto/ScanTest2.txt;;
	
  esac

counter=$(echo "$counter +1" | bc)

#break

done
print $counter






Thanks

Ziggy
 
np... got your star now :) I have 2 screens and the confirmation popped up out of view ó¿ó
 
just another question, I can't put my finger on this.... sometimes when I first login the menu does not fully load, it will only display the field requiring input. This only seems to happen on the mobile scanner, and after a few scans the screen seems to refresh.

But the confusing thing is it only does it once, if I log out and login again it is fine, so it does not really seem to be the program.

 
Hi

Personally I feel inclined to blame the terminal and/or [tt]tput[/tt]. Maybe the terminal failes to deliver correct environment information to [tt]tput[/tt] or [tt]tput[/tt] wastes so time with preparing its database for use.

Personally I would try it without [tt]tput[/tt], hoping that ANSI escape sequences will work on your terminal :
Code:
[gray]#!/bin/sh[/gray]

[navy]LOGO[/navy][teal]=[/teal][green][i]'RF Scan Menu'[/i][/green]
[navy]bold[/navy][teal]=[/teal][green][i]'[/i][/green][lime][i]\033[/i][/lime][green][i][1m'[/i][/green]
[navy]offbold[/navy][teal]=[/teal][green][i]'[/i][/green][lime][i]\033[/i][/lime][green][i][0m'[/i][/green]
[navy]counter[/navy][teal]=[/teal][purple]1[/purple]
[navy]ORDN[/navy][teal]=[/teal][green][i]''[/i][/green]
[navy]stmp[/navy][teal]=[/teal][green][i]"$( date )"[/i][/green]
[navy]amenu[/navy][teal]=[/teal][green][i]'Type exit to close'[/i][/green]

[b]while[/b] [teal]:;[/teal] [b]do[/b]

  clear

  [COLOR=chocolate]printf[/color] [green][i]"[/i][/green]
[lime][i]\t[/i][/lime][green][i]$bold Company $offbold[/i][/green]
[lime][i]\t[/i][/lime][green][i]$bold %s $offbold[/i][/green]

[lime][i]\t[/i][/lime][green][i]xxxxxxxxxxxxxxxxxxxxxx[/i][/green]
[lime][i]\t[/i][/lime][green][i]x %-18s x[/i][/green]
[lime][i]\t[/i][/lime][green][i]xxxxxxxxxxxxxxxxxxxxxx[/i][/green]

[lime][i]\t[/i][/lime][green][i]Scan Barcode[/i][/green]

[green][i]"[/i][/green] [green][i]"$LOGO"[/i][/green] [green][i]"$amenu"[/i][/green]

  [b]if[/b] [teal][[[/teal] [green][i]"$ORDN"[/i][/green] [teal]==[/teal] [green][i]''[/i][/green] [teal]]];[/teal] [b]then[/b]
    echo -n [green][i]'[/i][/green][lime][i]\t[/i][/lime][green][i]Order: '[/i][/green]
    [COLOR=chocolate]read[/color] ORDN
    [COLOR=chocolate]continue[/color]
  fi

  echo [green][i]"[/i][/green][lime][i]\t[/i][/lime][green][i]Order: $ORDN[/i][/green][lime][i]\n[/i][/lime][green][i]"[/i][/green]

  echo -n [green][i]"[/i][/green][lime][i]\t[/i][/lime][green][i]Scan ( $(( counter++ )) ) : "[/i][/green]
  [COLOR=chocolate]read[/color] answer

  [b]case[/b] [green][i]"$answer"[/i][/green] [b]in[/b]
    [green][i]'exit'[/i][/green][teal])[/teal] [COLOR=chocolate]break[/color] [teal];;[/teal]
    [teal]*)[/teal] echo [green][i]"$ORDN,$answer,$stmp"[/i][/green] [teal]>>[/teal] [green][i]'/home/zigsto/ScanTest2.txt'[/i][/green] [teal];;[/teal]
  [b]esac[/b]

[b]done[/b]

clear
Tested with [tt]mksh[/tt].


Feherke.
 
thanks feherke

I'll have to come back to that because it seems a bit different from what I am working with.

I probably should do new posts, but this is bugging me right now.....


I am using this expression to extract a portion of a string, but it gives me an error if I use letters in the variable

let lblval=$(echo `expr substr $lbl 3 $upc1`)


lblval=RRRR: 0403-009 The specified number is not valid for this
command.



 
let is for number variables only. just leave it out

Code:
lblval=$(command)



HTH,

p5wizard
 
Hi

As p5wizard already pointed out the error, I can only criticize your style ( again ) ;-) .
[ul]
[li]no need for [tt]expr[/tt][/li]
[li]no need for that [tt]echo[/tt][/li]
[li]no need for 2 child processes[/li]
[/ul]
Code:
[navy]lblval[/navy][teal]=[/teal][green][i]"${lbl:2:upc1}"[/i][/green]


Feherke.
 
thanks p5wizard, that worked.

feherke, is your syntax giving me errors because I am using ksh and you are posting sh ? You last example gave me error, I tried exactly as you had it (curly braces).

error:

Code:
0403-011 The specified substitution is
 not valid for this command.
 
You should use a ksh93 version in order to use the ${parameter:eek:ffset:length} syntax.

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Hi

Ziggy said:
feherke, is your syntax giving me errors because I am using ksh and you are posting sh ?
It is KSH. ( See man ksh | Parameter Expansion. )

More exactly it is KSH93 syntax. Seems your is just KSH88.
Code:
[blue]master #[/blue] lbl='ZiggyS1'

[blue]master #[/blue] upc1=4

[blue]master #[/blue] lblval="${lbl:2:upc1}"

[blue]master #[/blue] echo "$lblval"                                  
ggyS

[blue]master #[/blue] echo "$KSH_VERSION"                             
@(#)MIRBSD KSH R33 2008/04/11
Then you will have to keep using [tt]expr[/tt], but the [tt]echo[/tt] and one child process can still be removed :
Code:
[navy]lblval[/navy][teal]=[/teal][green][i]"$( expr substr "$lbl" 3 "$upc1" )"[/i][/green]
( Note that you better quote your variables, because without them [tt]expr[/tt] would fail if $lbl contains IFS characters or is empty. )

Feherke.
 
yes our version is 88, thanks for the tips. I am making good progress. I need to go back and clean up my code, there are many things to keep in mind but I have learned a ton since I started this project.
 
feherke

had a chance to dissect this now....

This line...

Code:
echo  "\tScan ( $(( counter++ )) ) : "

returns this error...

Code:
counter ++ : 0403-053 Expression is not complete; more tokens expe
cted.

I am not clear how it works, I gather it is a "Counter" and should display the quantity scanned.

the other thing I am not clear on is how do I position where to "read", with "tput cup" I had cursor positions to work with.


is \t a shortcut for print?

 
Replace this:
$(( counter++ ))
with this:
$((counter+=1))

\t is a TAB char (tabulation)

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Thanks PHV,

I tried this script (posted by: feherke Feb 11 3:10 ), and it also has issue loading the menu complete on the first pass after logging into shell, I tried with ksh and sh, usually efter exiting the script and going back in the menu fully displays.

what is consistent is that the line being "Read" will always display, but things like the captions (except read line) or header do not.

*** this does not happen on a PC telnet, but only on



eg... first login....

Code:
Scan Barcode


        Order:



After exiting Script....

Code:
 Company
         RF Scan Menu

        xxxxxxxxxxxxxxxxxxxxxx
        x Type exit to close x
        xxxxxxxxxxxxxxxxxxxxxx

        Scan Barcode


        Order:

Telnet on Scanner (Symbol MC9090)

Wavelink CE Version 6.0.42

if you think this should go to another section in the forum, let me know.

thanks



 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top