[sh] While loop -> Expression recursion level exceeded


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting [sh] While loop -> Expression recursion level exceeded
# 1  
Old 04-07-2009
Question [solved][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 recursive calls. I suppose that the problem may be with the number of repetitions which indeed may be very high but the loop is bound to terminate. What can I use instead that would work?

Code:
A="START"
B="END"

while(($A=~$B))
do
{
echo Hello
A=$B
}
done


Last edited by machinogodzilla; 04-07-2009 at 08:08 PM..
# 2  
Old 04-07-2009
what is it that you're trying to do and in what shell?
here's a stab in the dark with Bourne shell:
Code:
#!/bin/sh

A="START"
B="END"

while [ "$A" != "$B" ]; do
   echo Hello
   A=$B
done

# 3  
Old 04-07-2009
The shell was tcsh but I used bash to run my scripts. With this syntax everything works perfectly. I tried to use the double parenthesis probably because they worked fine for other control statements... On a side, the code from my first post was also saying 'hello' twice Smilie

Thank you for the fix! Smilie
# 4  
Old 04-09-2009
Question Hanling values in while loop

Hi,
i have a scenario like
file 1
aaa=ddd
bbb=ccc
ccc =ddd
file 2
aaa=mmm
ttt=yyy
bbb=ggg

using awk function i get the key values for file1 (aaa,bbb,ccc)

sample code
------------
warn_msg=0
call_function() {
while read LINE
do
# key values of file1.txt and file 2.txt is compared, if any invalid parameter, i will set warn_msg=1

if [$? !=0 ]; then
warn_msg=1
fi
done < file2.txt
}

call_function ## calling the function
echo $warn_msg

output
------
0

here the key (ttt) is an invalid parameter.
if any invalid parameter occured within the while loop and if i check the value of warn_msg, it is 1, but after the function completes, the value of warn_msg is assigned to 0 but it should be 1. please provide me an answer.
# 5  
Old 04-10-2009
Here is my solution based on my very limited knowledge. It prints "error" for every key in file2 that doesn't appear in file1.

Code:
#!/bin/bash

awk -F= '{print $1}' < file1 > keys

while read LINE

do
        TMP=`echo $LINE | sed s/=.*//`
        awk -F= -v v=$TMP '{if (v==$1) i=1}END{if (i!=1) print "error"}' < keys
done < file2

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Red Hat

SSL certificate generation on OS level or application level

We have a RHEL 5.8 server at the production level and we have a Java application on this server. I know of the SSL certificate generation at the OS (RHEL) level but it is implemented on the Java application by our development team using the Java keytool. My doubt is that is the SSL generation can... (3 Replies)
Discussion started by: RHCE
3 Replies

2. Shell Programming and Scripting

Using a variable as a for loop expression

I'm writing a script to merge the xkcd webcomic tiles for comic 1110. So far, I have written about 100 lines, and instead of doing each quadrant of the image separately, I've decided to use functions to do this, repeating for every quadrant and using variables for each quadrant to make the function... (9 Replies)
Discussion started by: jbondhus
9 Replies

3. Shell Programming and Scripting

using regular expression in for loop

Hi, i want to use regular expression in a for loop like this. for var in "/Mar/2010" do echo "Usage for the date $var" -----and want to grep $var partten from a file-------- done and it is not working. I am new to shell scripting, any one has any idea how to do it. (5 Replies)
Discussion started by: tarakant
5 Replies

4. Shell Programming and Scripting

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") counter=0 sales=0 total=0 echo "enter sales price" read sales total=total+sales while test $sales ; do... (5 Replies)
Discussion started by: Ccccc
5 Replies

5. Solaris

Difference between run level & init level

what are the major Difference Between run level & init level (2 Replies)
Discussion started by: rajaramrnb
2 Replies

6. UNIX for Dummies Questions & Answers

Top level TCSH while Loop doen't work

Hey guys... I'm learning some shell scripting on OS X using the tcsh shell. For some reason... my while loop isn't executing right (or more likely I am doing something wrong.) Something as simple as this doesn't work: #!/bin/tcsh set g = 0 while ($g <10) echo "this" $g @ g =... (2 Replies)
Discussion started by: sprynmr
2 Replies

7. UNIX for Dummies Questions & Answers

Disk quota exceeded......

I keep on getting an error on my site saying I've got a 250GB dedicated server, and have used less than 200mb of that. The site has only been on the server for just over a month. What does this mean and how can I sort it? (8 Replies)
Discussion started by: thehaapyappy
8 Replies

8. Shell Programming and Scripting

Logfile Size exceeded ????

Hi, How to write a script which checks the size of a log file? I want that the log file contents to get cleared as soon as it increases 1 KB. Thanks (3 Replies)
Discussion started by: skyineyes
3 Replies

9. HP-UX

Count Exceeded Error on HP-UNIX

Sirs/Madame, On my HP-Unix, I came across an error GRECV-count exceeded and as a result of this, systems got hanged and server came down. Graceful shutdown too was not allowed. Kindly, Can anybody help me out in killing this issue Bhavani.R (0 Replies)
Discussion started by: bhavani2006
0 Replies

10. UNIX for Dummies Questions & Answers

SCO Openserver 5.0.7 NSTRPAGES Exceeded

Hello guys i'm getting this error on a sco 5.0.7 machine and i have no idea why i'm getting this error. I know how to encrease the value of NSTRPAGES, right now i have it up to 4000. I would like to know what is NSTRPAGES and what is causing this error to come up in my server. Thanks a... (2 Replies)
Discussion started by: josramon
2 Replies
Login or Register to Ask a Question