Register a domain and help support LQ
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 11-30-2010, 11:41 PM   #1
LQ Newbie
Registered: Nov 2010
Posts: 2

Rep: Reputation: 0
Simple While Loop

Ok I am wanting to figure out a simple script that will implement a while loop to make a simple text file with multiple entries eg.

userlist (file name)

now I know this is childs play but people got to start somewhere. Thanks in advance!
Old 11-30-2010, 11:54 PM   #2
LQ Guru
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 9,424

Rep: Reputation: 2823Reputation: 2823Reputation: 2823Reputation: 2823Reputation: 2823Reputation: 2823Reputation: 2823Reputation: 2823Reputation: 2823Reputation: 2823Reputation: 2823
Assuming you are scripting in bash, you can have a look here:
Old 12-01-2010, 10:36 AM   #3
LQ 5k Club
Registered: Aug 2005
Distribution: OpenSuse, Fedora, Redhat, Debian
Posts: 5,396
Blog Entries: 2

Rep: Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908
You seem to putting the cart before the horse. Before you conclude that you need a while loop, perhaps you should describe what is the nature of the input data, where it comes from, and how you will parse it, if necessary. You are describing a programming conditional statement, without mentioning any of the conditions. A more strictly bounded loop may be more appropriate, or perhaps no looping at all.
This does sound a bit like homework. Please describe your objective and support it with some sample data.

--- rod.
Old 12-02-2010, 12:52 AM   #4
LQ Newbie
Registered: Nov 2010
Posts: 2

Original Poster
Rep: Reputation: 0
This is what I have come up with

while [ $x -le 5 ]
echo "User,$x,user$"
x=$(( $x + 1 ))

when appended to a file it would create


I am using this file as variables to add ldap entries. Not exactly homework but it is class work, and yes im a noob lol. Thanks for the help LQ seems like a great place to be!
Old 12-02-2010, 01:01 AM   #5
LQ 5k Club
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,576
Blog Entries: 31

Rep: Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195
It works and congratulations on that

It could be more elegantly done using an arithmetic for loop (not tested):
for (( x=1; x<6; x++ ))
    echo "User,$x,user$"
BTW it's easier to read code you put it in code tags (that's a link to instructions or you may prefer to use "Advanced Edit" mode which has a # button for code tags).


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
simple loop playback olpu Puppy 2 05-02-2010 08:57 PM
A simple for loop in the prompt ? SpLaSh212 Linux - Newbie 2 03-01-2008 12:11 PM
Help with simple loop program in C Exsiss Programming 7 10-10-2007 07:48 AM
[c shell] simple for loop saiz66 Programming 1 09-28-2004 08:02 PM
Simple for loop lappen Programming 10 09-26-2004 07:36 AM

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