LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
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 06-09-2008, 08:25 PM   #1
midlifecrisis
LQ Newbie
 
Registered: Aug 2005
Location: Lilburn, Georgia
Distribution: Linux Red Hat 7.3 /Solaris 8
Posts: 15

Rep: Reputation: 0
How does one make an intentional loop?


Hello everyone,

I'm very new to BASH programming and can't find an example of how to make a loop that runs forever on purpose -I'm finding examples of people trying to stop their perpetual loop -only.

What I want to write is a script that copies files to a directory, then deletes those files -over and over again, until I hit Ctrl + C

I'm working in Linux Red Hat 7.2.
Thanks.
 
Old 06-09-2008, 08:32 PM   #2
stress_junkie
Senior Member
 
Registered: Dec 2005
Location: Massachusetts, USA
Distribution: Ubuntu 10.04 and CentOS 5.5
Posts: 3,873

Rep: Reputation: 335Reputation: 335Reputation: 335Reputation: 335
There are several guides to scripting in bash on the Internet. Here is one.

http://www.tldp.org/LDP/abs/html/
 
Old 06-09-2008, 08:32 PM   #3
jailbait
LQ Guru
 
Registered: Feb 2003
Location: Virginia, USA
Distribution: Debian 12
Posts: 8,337

Rep: Reputation: 548Reputation: 548Reputation: 548Reputation: 548Reputation: 548Reputation: 548
You can create an infinite loop by using a while statement where the test is never false. For example:

Code:
set i 0
while {$i<1}  {
  cp some files to a directory
  rm some files in a directory
  }
-------------------
Steve Stites
 
Old 06-09-2008, 08:35 PM   #4
adamben
Member
 
Registered: Feb 2007
Distribution: slackware,gentoo,ubuntu
Posts: 50

Rep: Reputation: 17
while : ; do cp /directory1/* /directory2/; rm /directory2/*; done

or, to include directories and add a little force:
while : ; do cp -R /directory1/* /directory2/; rm -rf /directory2/*; done

while true: ; do cp /directory1/* /directory2/; rm /directory2/*; done
 
Old 06-10-2008, 03:03 AM   #5
midlifecrisis
LQ Newbie
 
Registered: Aug 2005
Location: Lilburn, Georgia
Distribution: Linux Red Hat 7.3 /Solaris 8
Posts: 15

Original Poster
Rep: Reputation: 0
Thank you guys; I didn't realize that it was such a simple thing to accomplish.
 
  


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



Similar Threads
Thread Thread Starter Forum Replies Last Post
LXer: WMF vulnerability actually intentional? LXer Syndicated Linux News 0 01-13-2006 08:01 PM
Accidental or Intentional Restart? MBH Slackware 1 09-17-2005 07:04 AM
Intentional packet dropping - how can I do this? sokar Linux - Networking 1 04-12-2004 12:06 AM
never ending loop on make jods Linux - Software 1 04-02-2004 03:02 PM
Make Loop notsoevil Linux From Scratch 1 02-11-2002 02:51 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 10:47 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