LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 08-16-2004, 09:30 AM   #1
michael_util
Member
 
Registered: Feb 2004
Posts: 47

Rep: Reputation: 15
Unhappy variable with while loops


Hello,

I have a shell script that runs in a endless loop,

First I declare all my functions, then variables then the while loops start ... the loop never ends.

Now the little app seems to run great , I have a trap setup for SIGUP which runs a function that does a source on a config file. This is so I can change paramters on the fly.

Now it seems to work except for a few arrays don't seem to get updated, I ran some test and if Ido a source at the bottom of the while loop and make a change it is reflected, but with the SIGHUP it seems the some changes are not affected.

I feel this is because the while loop ... I hope this makes sense ... the short version is since I am stuck in a while loop, updating variables seems to be a pain in the $$$.

Thanks.

Michael.
 
Old 08-16-2004, 09:48 AM   #2
jim mcnamara
Member
 
Registered: May 2002
Posts: 964

Rep: Reputation: 36
post your while loop code, or the whole script if it isn't hundreds of lines long - don't forget code tags...
 
Old 08-16-2004, 10:16 AM   #3
michael_util
Member
 
Registered: Feb 2004
Posts: 47

Original Poster
Rep: Reputation: 15
Here is part of the script ... trimmed because of size

trap restart 1

function restart
{
. config_main
}

function getfile
{
echo $POSTFILE
}

. config_main

counter=0

while [ $counter -lt 5 ];
do
getfile
sleep 2
done

That is most of the code really ... so it seems that some of the variables do not get updated with a kill -1, but if I put a ". config_main" before the sleep all changes are noticed.

Michael.
 
Old 08-16-2004, 10:45 AM   #4
jim mcnamara
Member
 
Registered: May 2002
Posts: 964

Rep: Reputation: 36
counter is not local to this loop - it should be explicitly used in the loop not somewhere else, because it is controlling the loop. If you need to, move
. config_main inside the loop as well, it does not break anything.



Code:
while [ $counter -lt 5 ]
do
     getfile
     sleep 2
     let counter=$counter+1
done
 
Old 08-16-2004, 12:07 PM   #5
michael_util
Member
 
Registered: Feb 2004
Posts: 47

Original Poster
Rep: Reputation: 15
couter is not inside the loop because the loop should never end ... I supposed I could move the sourcing of config_main into the loop.

Michael.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
while loops + while : blizunt7 Linux - General 3 12-04-2004 05:27 PM
foreach loops chunky Linux - General 2 07-02-2004 11:49 AM
loops JMK Linux - Newbie 11 04-09-2004 05:30 PM
How to get 'Window' variable from a 'Widget' variable bordel Programming 0 11-19-2003 03:19 AM
Functions And Loops petercool Programming 14 08-08-2003 10:35 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 08:22 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration