Did you know LQ has a Linux Hardware Compatibility List?
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
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!


  Search this Thread
Old 08-29-2008, 07:00 AM   #1
LQ Newbie
Registered: Aug 2008
Posts: 24

Rep: Reputation: 0
Cool Make a bash script loop from start

Hi all, I am very new to Linux and I have a question.

How can I get a bash script to keep looping from the start "without" using any goto commands

for example my script has the following commands . . .

sleep 1

. . . but then I want it to start all over again from the "w" command and keep doing so untill stop it.

Any assistance would be a real help to me


Old 08-29-2008, 07:16 AM   #2
Senior Member
Registered: Jun 2005
Location: England
Distribution: SLED, openSUSE
Posts: 1,055

Rep: Reputation: 180Reputation: 180
Make the last line of the script

exec $0
Old 08-29-2008, 07:20 AM   #3
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1966Reputation: 1966Reputation: 1966Reputation: 1966Reputation: 1966Reputation: 1966Reputation: 1966Reputation: 1966Reputation: 1966Reputation: 1966Reputation: 1966
Hi and welcome to LQ! How do you suppose to stop the process? You can try an infinite loop like the following and stop it using Ctrl-C
while true
  your commands here
Old 08-29-2008, 07:20 AM   #4
Senior Member
Registered: May 2008
Posts: 3,810

Rep: Reputation: 1230Reputation: 1230Reputation: 1230Reputation: 1230Reputation: 1230Reputation: 1230Reputation: 1230Reputation: 1230Reputation: 1230
while true
  echo "Some commands to loop endlessly go here."
edit: damn, beaten to it.
Old 08-29-2008, 07:32 AM   #5
LQ Newbie
Registered: Aug 2008
Posts: 24

Original Poster
Rep: Reputation: 0
Thumbs up Working perfect!!!

Thanks for your help everyone, it's working perfect now!!
Old 08-29-2008, 12:37 PM   #6
Registered: Oct 2007
Location: MI
Distribution: Debian Slackware
Posts: 528

Rep: Reputation: 50
Sounds like homework to me???


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
how to loop over text file lines within bash script for loop? johnpaulodonnell Linux - Newbie 9 07-28-2015 04:49 PM
How to make a bash script to start & end apache and mysql ? rova Programming 2 03-01-2008 08:27 PM
bash script loop bong.mau Programming 6 09-14-2005 08:38 PM
bash script for loop drisay Programming 5 12-25-2004 01:32 AM
bash script - for loop question rignes Programming 3 10-06-2004 12:16 AM

All times are GMT -5. The time now is 12:53 PM.

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