LinuxQuestions.org
Visit the LQ Articles and Editorials section
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-14-2010, 05:38 AM   #1
stp001
LQ Newbie
 
Registered: Mar 2010
Posts: 5

Rep: Reputation: 0
Smile Bash infinite loop problem?


Hi guys ,
I am writing a bash that's quite simple ,having zenity dialog boxes.
I seem to have a problem with the infinite loop.
as soon as it reaches the loops , the script exits without entering the loop.
I couldn't find concrete examples of inner infinite loops in Bash.

here's the loop:

for param in $ans
do
while [ 1 ]
do

test_pram= $(zenity --entry --text "Please \ enter $param for the webpage")
if [ $? -eq 0 ] || [ -n "$test_pram" ] ; then
break
fi
done
done

Please help
Thanks

Last edited by stp001; 03-14-2010 at 05:44 AM. Reason: miss typing
 
Old 03-14-2010, 05:43 AM   #2
GrapefruiTgirl
Guru
 
Registered: Dec 2006
Location: underground
Distribution: Slackware64
Posts: 7,594

Rep: Reputation: 550Reputation: 550Reputation: 550Reputation: 550Reputation: 550Reputation: 550
Hiya! Welcome to LQ.

First things first: Please put code into code tags, so it is more readable, and so that any formatting that might be present, will be preserved. Here's how to use code tags: http://www.phpbb.com/community/faq.php?mode=bbcode#f2r1

Now.... Unless that's a typo, there is a SPACE between the test_pram= and the $(zenity.. thing, which will mean that the variable will always be empty, and your zenity ccommand, if it works, will just execute and return nothing useful to the script.

If there's more than that wrong, I don't see it at this moment -- I'm tired, and going to sleep soon

Cheers,
Sasha

PS -- instead of the while true; do that you are using, how about something more like:
Code:
while [ ! "$test_pram" ]; do
which will repeat the loop until $test_pram has some contents?

Last edited by GrapefruiTgirl; 03-14-2010 at 05:46 AM.
 
Old 03-14-2010, 05:45 AM   #3
jamescondron
Member
 
Registered: Jul 2007
Location: Scunthorpe, UK
Distribution: Ubuntu 8.10; Gentoo; Debian Lenny
Posts: 961

Rep: Reputation: 69
Well ideally sub 'while[1]' for 'while true', but what is in $ans? And why does that need an infinite loop? It'll only ever loop over the first element in $ans.
 
Old 03-14-2010, 05:56 AM   #4
stp001
LQ Newbie
 
Registered: Mar 2010
Posts: 5

Original Poster
Rep: Reputation: 0
Thanks

Thanks for your help I'll try to figure out
 
Old 03-14-2010, 09:14 AM   #5
jamescondron
Member
 
Registered: Jul 2007
Location: Scunthorpe, UK
Distribution: Ubuntu 8.10; Gentoo; Debian Lenny
Posts: 961

Rep: Reputation: 69
If you give us your whole script we can give you a much better answer
 
Old 03-15-2010, 05:35 AM   #6
stp001
LQ Newbie
 
Registered: Mar 2010
Posts: 5

Original Poster
Rep: Reputation: 0
The main idea of this script is that you collect a string of values from a zenity checklist and then use the zenity entry
dialogbox
to type these parameters that you latter on embed in an Html page.I want the entry dialogbox to stay there unless you type something and click OK.Any advance help or references on how to best use dialog boxes will be appreciated.The problem is that there are no modal dialog boxes in zenity which makes the task difficult.

Code:
#!/bin/bash

#set -x
IFS_OLD= $IFS

answers=$(zenity --list  --text "please check all parameters for the Web page" --checklist  --column "Pick" --column "Parameters"  TRUE "title" TRUE "H1" TRUE "para1" TRUE "para2"  TRUE "imageURL" \
 --separator=":") ; echo "$answers"

IFS=':' 
arrAns=""
inc=0

for param in  $answers
#while [[ $inc -le ${#parray[@]} ]] 
   do

   while true
      do 
         test_param= $(zenity --entry --text "Please enter $param  for the webpage")
	      
          if [ $? -eq 0 ]  &&  [ "$test_param" != " " ] ; then
	   arrAns["$inc"]= $test_param
           inc= $(( inc++ ))
	   break 
	  fi       
    done	
done
	
#echo ${#arrAns[@]}
IFS=OLD_IFS

 zenity --info --text "In the next screen,please select the file to add as preformatted text into your webpage"



myFile= $(zenity --file-selection --title="Select a File")
IFS=$IFS_OLD

echo "<html>

 <head>

<title>"${arrAns[1]}"</title>

</head>

<body bgcolor=$bgColor>

<font color=$fgColor>

<h1>"${arrAns[2]}"</h1>

<p>"${arrAns[3]}"</p>

<p><img src="${arrAns[3]}" /></p>

<p> `cat "$myFile"` </p>

</font>

</body>

   </html>" > ~/public_html/$filename



zenity --info --text "Congrats !! Your Webpage has been created\nType this URL into your browser to confirm:\nhttp://mysite.com/~`$(whoami)`/$filename"
#EOF

Last edited by stp001; 03-15-2010 at 12:19 PM.
 
Old 03-15-2010, 06:56 AM   #7
jamescondron
Member
 
Registered: Jul 2007
Location: Scunthorpe, UK
Distribution: Ubuntu 8.10; Gentoo; Debian Lenny
Posts: 961

Rep: Reputation: 69
Well, my take on the loop in question, or more or less. When I execute yours the loop is all very odd.
Code:
#!/usr/bin/env bash

OLD_IFS=$IFS
IFS=":"

answers=$(zenity --list  --text "please check all parameters for the Web page" --checklist  --column "Pick" --column "Parameters"  TRUE "title" TRUE "H1" TRUE "para1" TRUE "para2"  TRUE "imageURL"  --separator=":") 

arr_ans=""
inc=0

for param in ${answers[@]}; do
    test_param=""
    # Here, as per 'while test_param == "" or test_param == "some entry that results in err etc"
    # By setting t_p above we can happily use a while loop here without any issue.
    test_param=$(zenity --entry --text "Please enter $param for the webpage")
    arr_ans=( ${arr_ans[@]-} $( echo "$test_param" ) )
done 

# And so on
 
  


Reply

Tags
bash, infinite, loops, scripting, zenity


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
Problem with char driver write function - infinite loop Cherubim Linux - Kernel 1 10-13-2009 01:08 AM
Bash script - Infinite loop caused by a logical OR operator skuzye Programming 9 02-04-2009 01:31 PM
RHEL 5 Install Problem - Infinite Reboot Loop aramsey Linux - Enterprise 4 09-19-2008 04:22 AM
Apache mod_rewrite CondRewrite infinite loop problem jika Linux - Server 2 05-01-2007 07:25 AM
facing problem in increment operator of set :infinite LOOP ashwinipahuja Programming 0 06-03-2004 12:05 AM


All times are GMT -5. The time now is 01:15 PM.

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