LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices

Reply
 
Search this Thread
Old 03-17-2010, 06:14 PM   #1
stp001
LQ Newbie
 
Registered: Mar 2010
Posts: 5

Rep: Reputation: 0
Bash infinite loop problem haunting


Hi
I want to figure out what is going on in this small script.Its really strange.I think its the infinite loop again.All I want to do is to collect some data from the zenity dialog box in an array and then echo it.
Here is the code
Code:
#!/bin/bash
#export PS4='+${BASH_SOURCE}:${LINENO}:${FUNCNAME[0]}: ' debugging info

IFS_OLD= $IFS
#IFS=':' 
result



function pageInfo {

local num
 arr_local

 for (( i=0 ; i<5 ; i++ ))
  do
	while true

           test_param= $(zenity --entry --text "Please enter $param  for the webpage")
	      
           if [[  -n "$test_param"  && "$?" -eq  0  ]] ; then
	       arr_local["$num"]=$test_param 
                        (( num++ ))
		break             
	   fi

	  done
     
 done	
  echo ${arr_local[@]}      
	
}

result=(`pageinfo`)
echo "$result"
#EOF
Thanks
 
Old 03-17-2010, 06:22 PM   #2
smoker
Senior Member
 
Registered: Oct 2004
Distribution: Fedora Core 4, 12, 13, 14, 15, 17
Posts: 2,279

Rep: Reputation: 248Reputation: 248Reputation: 248
Is $num null or zero ?
 
Old 03-17-2010, 06:22 PM   #3
colucix
Moderator
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,488

Rep: Reputation: 1956Reputation: 1956Reputation: 1956Reputation: 1956Reputation: 1956Reputation: 1956Reputation: 1956Reputation: 1956Reputation: 1956Reputation: 1956Reputation: 1956
You did not provide many details about what you got from running this script (error messages, unpredictable results and so on). Anyway, two syntax errors come at first sight:
Code:
IFS_OLD= $IFS
and
Code:
test_param= $(zenity --entry --text "Please enter $param  for the webpage")
In assignments there must not be extra spaces around the equal sign. It should be:
Code:
test_param=$(command)
 
Old 03-17-2010, 06:29 PM   #4
chrism01
Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.5, Centos 5.10
Posts: 16,261

Rep: Reputation: 2028Reputation: 2028Reputation: 2028Reputation: 2028Reputation: 2028Reputation: 2028Reputation: 2028Reputation: 2028Reputation: 2028Reputation: 2028Reputation: 2028
Also, you don't call fn that way
Code:
result=(`pageinfo`)

should be

result=pageInfo
note also you spelled the fn name wrong
Try running with
Code:
#!/bin/bash

# This line shows what bash is really doing
set -xv
 
Old 03-17-2010, 06:32 PM   #5
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Arch/XFCE
Posts: 17,802

Rep: Reputation: 728Reputation: 728Reputation: 728Reputation: 728Reputation: 728Reputation: 728Reputation: 728
Two nits:

--You don't say exactly what is (or is not) happening.

--You can add echo statements to check on what is happening in different parts of the script.
 
Old 03-17-2010, 06:43 PM   #6
smoker
Senior Member
 
Registered: Oct 2004
Distribution: Fedora Core 4, 12, 13, 14, 15, 17
Posts: 2,279

Rep: Reputation: 248Reputation: 248Reputation: 248
I don't see how an uninitialised variable can be used as an index in an array.
If I run
Code:
echo "$num"
((num++))
echo "$num"
I get
Code:
user@shell>

1
So arr_local["$num"]=$test_param has no index.

Wouldn't $i be more useful there ?

Last edited by smoker; 03-17-2010 at 06:51 PM.
 
  


Reply

Tags
bash, infinite, loop, script


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
Bash infinite loop problem? stp001 Linux - Newbie 6 03-15-2010 06:56 AM
Bash infinite loop problems? stp001 Programming 2 03-14-2010 02:41 PM
Bash script - Infinite loop caused by a logical OR operator skuzye Programming 9 02-04-2009 01:31 PM
Apache mod_rewrite CondRewrite infinite loop problem jika Linux - Server 2 05-01-2007 07:25 AM


All times are GMT -5. The time now is 04:24 AM.

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration