Null Handling in Until loop. . .loop won't stop


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Null Handling in Until loop. . .loop won't stop
# 1  
Old 11-24-2009
Power Null Handling in Until loop. . .loop won't stop

Hi Im running this script, which is supposed to find the max value build some tables and then stop running once all the tables are built. Thing is , it keeps assigning a null value to $h and then $g is null so it keep building tables i.e. testupdateNUL. How can I stop this? Here is what I have:

Code:
j=`/usr/local/mysql/bin/mysql --skip-column-names $US $PW $DB -e "select count(*) from loyalmarkets" ;`
echo $j
limit=$j
var=0
until ((limit=var)); do
h=`/usr/local/mysql/bin/mysql --skip-column-names $US $PW $DB -e "select max(orgunit1) from loyalmarkets where orgunit1 !=' ';"`
echo $h
g=`echo $h | cut -c1-3`
echo loyaltest$g
end=`date +%F`
limit=$j
var=0
until ((limit=var)); do
h=`/usr/local/mysql/bin/mysql --skip-column-names $US $PW $DB -e "select max(orgunit1) from loyalmarkets where orgunit1 !=' ';"`
echo $h
g=`echo $h | cut -c1-3`
echo loyaltest$g
end=`date +%F`
echo $end
/usr/local/mysql/bin/mysql --skip-column-names $US $PW $DB -e "drop table if exists testupdate$g; create table testupdate$g type=myisam as select store_name, account_id, local_request_date, order_id, svat
ran_type_id, amount, promo_program_id from request_detail rd force index(local_request_date)join store s on rd.store_id = s.store_id and orgunit1 = '$h' where rd.local_request_date >= '$end' - interval 1 day andrd.local_request_date < '$end' and currency_type_id = 2 and svatran_type_id in (2,4,6) limit 10; delete from loyalmarkets where orgunit1 = '$h';"
done


Last edited by pludi; 11-24-2009 at 04:27 PM.. Reason: code tags, please...
# 2  
Old 11-24-2009
Try
Code:
((limit == var))

As it was written above it means: assign the value of var to limit. The value of limit determines the outcome, if more than 0 then the outcome is true.

Last edited by Scrutinizer; 11-24-2009 at 05:05 PM..
# 3  
Old 11-24-2009
Thanks for looking. Unfortunately that did not work. . . .
# 4  
Old 11-24-2009
Well it was just a start. There are more issues:
  • limit and/or var never get changed inside the loop so the loop never ends
  • there is only one done statement
  • there are unnecessary repeats of the same code

This code needs a bit of fixing. You might want to try indenting your code for clarity.
# 5  
Old 11-24-2009
I see var set to zero before the internal until, I see limit set to $j, but nothing ever changes it -

You have two until's and one done. The code as shown can't be running - it would die with "syntax error: unexpected end of file"
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

awk loop using array:wish to store array values from loop for use outside loop

Here's my code: awk -F '' 'NR==FNR { if (/time/ && $5>10) A=$2" "$3":"$4":"($5-01) else if (/time/ && $5<01) A=$2" "$3":"$4-01":"(59-$5) else if (/time/ && $5<=10) A=$2" "$3":"$4":0"($5-01) else if (/close/) { B=0 n1=n2; ... (2 Replies)
Discussion started by: klane
2 Replies

2. Shell Programming and Scripting

How to stop infinite loop

Im unable to stop the below infinite loop (bash script). Can someone tell me why this isnt responding to signals eg: ctrl+c (SIGINT) or ctrl+z c=0 test_loop() { c=$(($c+1)) echo "count value is : $c " sleep 1 test_loop } Im using: SunOS 5.10 PS: If run this as... (13 Replies)
Discussion started by: Arun_Linux
13 Replies

3. Shell Programming and Scripting

problem handling lov in FOR loop

Hi all, i am trying to process a list of values in FILE like this: aaa:bbb ccc:ddd eee:fff With the following logic: for INFO in FILE do export F1=`cut -f1,3,5,7 -d":" < FILE` export F2=`cut -f2,3,5,7 -d":" < FILE` ssh $F1 bash <<EOF echo $F1 echo $F2 date (10 Replies)
Discussion started by: jonnyd
10 Replies

4. Shell Programming and Scripting

Loop to read parameters and stop

Hey guys, How do I make a loop that reads all the parameters en then stop when there are no parameters anymore ? Something that gives an output like this: ./Script.sh parameter1 parameter2 parameter3 parameter = parameter1 parameter = parameter2 parameter = parameter3 Thanks a lot,... (5 Replies)
Discussion started by: Miki1579
5 Replies

5. Shell Programming and Scripting

howto stop loop iteration

I wonder how to stop further loop iterations when conditions gets false e.g. This file.txt contains the following structure : 1 2 3 4 5 6 7 8 9 10 How to stop iteration when if statement gets false ? for n in `cat file.txt` do if (( n<=5 )) (1 Reply)
Discussion started by: presul
1 Replies

6. Shell Programming and Scripting

Basic While loop won't exit...

Hi everyone - just like to say great forum...I've learned a lot off here but I just can't figure this one out...(first post) I'm writing a script to monitor a directory and email the latest modified file....(I realize there are better ways than I'm trying here...I don't like copying and pasting... (5 Replies)
Discussion started by: trevthefatty
5 Replies

7. Shell Programming and Scripting

Using variables created sequentially in a loop while still inside of the loop [bash]

I'm trying to understand if it's possible to create a set of variables that are numbered based on another variable (using eval) in a loop, and then call on it before the loop ends. As an example I've written a script called question (The fist command is to show what is the contents of the... (2 Replies)
Discussion started by: DeCoTwc
2 Replies

8. Shell Programming and Scripting

String handling is not working inside if loop

Hi All, I am comparing two strings inside an if condition if the strings are same then it should go inside the loop else it should execute code given in else part. But there is a but inside my script Even if the if condition is true it is not going inside the loop also it is executing... (4 Replies)
Discussion started by: usha rao
4 Replies

9. UNIX for Dummies Questions & Answers

Anyone know?: How the 'for'-loop could stop working in interactive bash shell?!

It is happening with my sessions already second time: a 'for'-loop for some reason stop to work as expected. That means or it is looping without exitting, or it is not loop even once. Here example of my try when it is not processing even one loop. You can see, I start new subshell and... (14 Replies)
Discussion started by: alex_5161
14 Replies

10. Programming

how to stop execution in for loop

Hi all, I am working on a c source code nearly 2000 line . it contains one big for( i=0; i< 200 ; i++ ) loop of around 600 lines could any tell me how to break the execution of prog when the value of i is 50 in for loop so that i can check inside the loop. Thanks.. (1 Reply)
Discussion started by: useless79
1 Replies
Login or Register to Ask a Question