LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 12-20-2006, 08:42 PM   #1
rollo
Member
 
Registered: Apr 2004
Location: France
Distribution: Debian Sid (Kanotix)
Posts: 237

Rep: Reputation: 30
How to loop a script?


Hi. Simple question here about bash scripts.

I have a script I use for scanning documents. Due to a hardware problem I can't scan in batches. So instead of exiting after each document, I want the script to loop and ask "Start again?".

This is as far as I've got:

Code:
dialog --yesno "Go ahead?"
if [ $? -eq 0 ] ; then

[script here]

else exit
fi
If I can loop that, then there will be a way to get out after each scan. But even the dialog is overkill, surely...?

Ideas appreciated!
 
Old 12-20-2006, 09:09 PM   #2
homey
Senior Member
 
Registered: Oct 2003
Posts: 3,057

Rep: Reputation: 61
Maybe this will get you started...
Code:
#!/bin/bash

while true ; do
clear
tput cup 3 16; echo "Scan Menu"
tput cup 4 12; echo "~~~~~~~~~~~~~~~~~~~"
tput cup 6 12; echo "1. Run a scan job"
tput cup 7 12; echo "2. Exit from menu"
tput cup 9 12; echo -n "Please enter your choice (1-2): "

read sel

case $sel in
1) ./myscript ;;

2) exit ;;

esac
sleep 10
done
You can also press Ctrl c to end the menu script
 
Old 12-21-2006, 02:45 AM   #3
rollo
Member
 
Registered: Apr 2004
Location: France
Distribution: Debian Sid (Kanotix)
Posts: 237

Original Poster
Rep: Reputation: 30
Thumbs up Cheers

That got me started - and finished. And I even learned something in between!

Thanks homey, I appreciate it.

Rollo
 
Old 12-21-2006, 05:39 AM   #4
homey
Senior Member
 
Registered: Oct 2003
Posts: 3,057

Rep: Reputation: 61
You're welcome!
 
  


Reply



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 On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
bash script loop bong.mau Programming 6 09-14-2005 07:38 PM
how to implement an endless loop in a rc startup script garba Linux - General 6 05-03-2005 11:30 AM
bash script for loop drisay Programming 5 12-25-2004 12:32 AM
bash script - for loop question rignes Programming 3 10-05-2004 11:16 PM
Loop in this perl script is not working meluser Programming 2 04-01-2003 08:59 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 11:48 AM.

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