Expression recursion level question


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Expression recursion level question
# 1  
Old 03-09-2010
Expression recursion level question

Hi. I am receiving this error message for the highlighted line (let "total=$total+$sales").
line 11: let: total+sales:expression recursion level exceeded (error token is "total+sales")

Code:
counter=0
sales=0
total=0
echo "enter sales price"
read sales
total=total+sales
while test $sales  ;  do
let "counter=$counter+1"
let "total=$total+$sales"
done
echo $sales
echo $counter
echo $total

Is anyone familiar with this error message?
Thank you
# 2  
Old 03-09-2010
The message is somewhat misleading but is caused by your while loop.
Code:
while test $sales  ;  do
   let "counter=$counter+1"
   let "total=$total+$sales"
done

This loop will run forever until you kill the process. You need to modify your test of $sales to provide a loop termination condition.
# 3  
Old 03-09-2010
You have a couple of logic errors, and some syntax changes needed.

Code:
counter=0
sales=0
total=0

echo "enter sales price"
read sales

while [ $sales -ne 0 ]  ;  do
   echo "enter sales price \c"  # echo -n with no \c in bash
   read sales
   
   counter=$((counter+1))
   let total=$((total+sales))
done
echo $sales
echo $counter
echo $total

use the $(( )) construct for integer arithmetic operations

Note: shell will not do floating point operations, i.e., 1.3 +
2.75, natively. You have to invoke a utility like bc.
# 4  
Old 03-09-2010
Recursion err (continued)

Thank you fp and Jim McNamara.

Jim, why are there two instances of:Smilie

Code:
echo "enter sales price"
read sales
. . .
while. . .
echo "enter sales price \c"
read sales

Again thanks for the jump start.
Ccccc

P.S. I'm getting zeroes for "sales" & "counter" and blank for total.
# 5  
Old 03-09-2010
# 6  
Old 03-10-2010
Methyl, thank you for pointing this out. I am closing this thread as a duplicate. Please continue the discussion on the other thread, i.e. https://www.unix.com/shell-programmin...ning-wild.html
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Regular expression question

Hi guys, I need a help with a query. Basically i want to know the difference between (0+01)* and ((0+01)*)* . It seems whatever string can be generated by the first RE can also be generated by second and they should essentially be same. Am i missing something? (1 Reply)
Discussion started by: srkmish
1 Replies

2. Shell Programming and Scripting

Question on returning back a level with menus

Hi Agian Sorry for all these questions...: Last one for a whie, I promise This is an example of a menu script I am using. It works OK...when I get to the 2nd menu level, if the command is issued or canceled, I would like to go back to the first menu (# MAIN SECTION) This is NOT the... (7 Replies)
Discussion started by: olearydc
7 Replies

3. UNIX for Dummies Questions & Answers

General question about folder level permissions

How is the level of access on a particular folder determined? I have heard (its just hearsay so am not particularly sure of it) that the access a particular user/group has to a low level directory is also affected by the level of access granted to the user/group on its parent directories. e.g. ... (1 Reply)
Discussion started by: jawsnnn
1 Replies

4. UNIX for Dummies Questions & Answers

Regular Expression Question

Hello, I'm trying to rename a bunch of files that were named incorrectly. I know a little about regular expressions but I'm not very good at them. Here is the image of the file names: http://i47.tinypic.com/np2gxi.jpg I'm trying to change the 20111116 at the beginning to 20101116 for all... (2 Replies)
Discussion started by: nastyn8
2 Replies

5. Shell Programming and Scripting

[sh] While loop -> Expression recursion level exceeded

Hi! I wanted to use a while loop, like the one below, for checking words extracted by awk to terminate when a specific word appears. Unfortunately whenever I put my code inside the loop I get an error "Expression recursion level exceeded". What does it mean? What recursion? I don't have any... (4 Replies)
Discussion started by: machinogodzilla
4 Replies

6. UNIX for Dummies Questions & Answers

Regular Expression question

Folks; I have 3 questions & any help with them would be really appreciated: If i have a list of directories, for example: /fs/pas/2007/4/6/2634210/admdat/examin /fs/pas/2007/4/6/2634210/admdat2/stat /fs/pas/2007/4/6/2634210/admdat3/data /fs/pas/2007/4/6/2634210/im_2/0b.dcm Now; my... (6 Replies)
Discussion started by: Katkota
6 Replies

7. Shell Programming and Scripting

A Question On Recursion In Ksh

Hi Folks, I would just like to know how recursion works in ksh or inside a shell in general. I created the following script, but it works(runs recursively) only for 64 times: ---------------- #! /usr/bin/ksh displaymessage() { echo "displaying count: $cnt " echo "wait for 1 second..."... (1 Reply)
Discussion started by: marlonus999
1 Replies

8. UNIX for Dummies Questions & Answers

Regular Expression Question

Hi - I am trying to ignore the following items from a list. lp0 lp11 lp12 lp14 The following code works fine, but I was wondering if there was a tidier way to write the lp regular expression? egrep -v "lp" Thanks in advance. (3 Replies)
Discussion started by: Krispy
3 Replies

9. Shell Programming and Scripting

question about regular expression

why does * highlight everything in it... shouldn't it only highlight capital letters? (0 Replies)
Discussion started by: brentdeback
0 Replies

10. UNIX for Dummies Questions & Answers

enterprise level permissions question?

Can someone give me an example of Enterprise level permissions? (4 Replies)
Discussion started by: wmosley2
4 Replies
Login or Register to Ask a Question