LinuxQuestions.org
LinuxAnswers - the LQ Linux tutorial section.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 10-26-2007, 07:18 AM   #1
IceOner
LQ Newbie
 
Registered: Oct 2007
Location: Amsterdam
Distribution: Debian, ubuntu
Posts: 9

Rep: Reputation: 0
Question while loop question


Hi all,


I have a question. I want to create a while loop, but don't really know how to tackle this one.

It is, while [file doesn't exist] do.

I don't know alot of options for the while loop in bash, can you guys'n'gals help me out?
 
Old 10-26-2007, 07:26 AM   #2
Guttorm
Senior Member
 
Registered: Dec 2003
Location: Trondheim, Norway
Distribution: Debian and Ubuntu
Posts: 1,136

Rep: Reputation: 230Reputation: 230Reputation: 230
Code:
while [ ! -e /tmp/filename.txt ]
do
        echo "File does not exist";
        sleep 3
done
echo "Now it does"
 
Old 10-26-2007, 07:28 AM   #3
ta0kira
Senior Member
 
Registered: Sep 2004
Distribution: FreeBSD 9.1, Kubuntu 12.10
Posts: 3,078

Rep: Reputation: Disabled
Well, how much programming background do you have? Do you understand the different types of loop, basic statements, conditions, etc.? Do you understand how statements are composed in bash (out of command-line programs and built-ins)?
ta0kira
 
Old 10-26-2007, 07:29 AM   #4
unSpawn
Moderator
 
Registered: May 2001
Posts: 27,279
Blog Entries: 54

Rep: Reputation: 2852Reputation: 2852Reputation: 2852Reputation: 2852Reputation: 2852Reputation: 2852Reputation: 2852Reputation: 2852Reputation: 2852Reputation: 2852Reputation: 2852
Code:
while [ ! -e "/some/filename" ]; do echo -en "no "; done

http://www.tldp.org/HOWTO/Bash-Prog-Intro-HOWTO.html
http://www.tldp.org/LDP/Bash-Beginne...tml/index.html
http://www.tldp.org/LDP/abs/html/
 
Old 10-26-2007, 07:34 AM   #5
IceOner
LQ Newbie
 
Registered: Oct 2007
Location: Amsterdam
Distribution: Debian, ubuntu
Posts: 9

Original Poster
Rep: Reputation: 0
OK.. Cool thanks..

And to answer your question about my background.
I do quite understand the basic workings of loops..
But haven't been bash programming for quite some time.. (like over three years )
I forgot a lot of the options (-ne -le etc.etc.)..

Anyone know a good overview of those options for the different looptypes?
 
Old 10-26-2007, 08:13 AM   #6
Hobbletoe
Member
 
Registered: Sep 2004
Location: Dayton, Oh
Distribution: Linux Mint 10, Linux Mint 11
Posts: 148

Rep: Reputation: 18
Appendix B (specifically Table B-2 and Table B-3) of the Advanced Bash Scripting Guide might be what you want.
 
Old 10-26-2007, 08:23 AM   #7
IceOner
LQ Newbie
 
Registered: Oct 2007
Location: Amsterdam
Distribution: Debian, ubuntu
Posts: 9

Original Poster
Rep: Reputation: 0
That is exactly what i meant.
Thank you very much
 
  


Reply


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 script Question while loop glennph93 Programming 6 05-25-2007 03:27 PM
BASH 'while' loop question GSMD Programming 4 04-13-2007 12:51 AM
vbs loop question jonlake Programming 3 10-05-2006 05:32 PM
bash script - for loop question rignes Programming 3 10-05-2004 11:16 PM
newbie python question: doing more than one thing in a for loop SerfurJ Programming 1 03-18-2004 10:14 AM


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