LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Desktop
User Name
Password
Linux - Desktop This forum is for the discussion of all Linux Software used in a desktop context.

Notices


Closed Thread
  Search this Thread
Old 03-26-2008, 05:58 PM   #1
snorkytheweasel
LQ Newbie
 
Registered: Oct 2007
Posts: 5

Rep: Reputation: 0
BASH - while loop


[ This is cross-posted to the newbies forum ]

Why doesn't this work? It's just a simple while loop

#!/bin/sh

src='/home/sites/$sitenum/web'
sitenum = 1
limit = 8
while [ $sitenum < $limit ];
do
echo 'The location is $src'
let $sitenum = $sitenum + 1
done

What I expect to see is

The location is /home/sites/1/web
The location is /home/sites/2/web
The location is /home/sites/3/web
The location is /home/sites/4/web
The location is /home/sites/5/web
The location is /home/sites/6/web
The location is /home/sites/7/web

The errors are
[sitenum: command not found
[sitenum: command not found
[sitenum: command not found
[sitenum: command not found
[sitenum: command not found
[sitenum: command not found
sitenum: command not found (Note: that line is different from the ones above it)
limit: command not found
$limit: ambiguous redirect
 
Old 03-26-2008, 06:16 PM   #2
manwichmakesameal
Member
 
Registered: Aug 2006
Distribution: Slackware
Posts: 804

Rep: Reputation: 110Reputation: 110
Try using
Code:
sitenum=1
limit=8
instead. Notice the spaces are gone.
 
Old 03-26-2008, 09:36 PM   #3
reddazz
LQ Guru
 
Registered: Nov 2003
Location: N. E. England
Distribution: Fedora, CentOS, Debian
Posts: 16,298

Rep: Reputation: 77
Please post your thread in only one forum. Posting a single thread in the most relevant forum will make it easier for members to help you and will keep the discussion in one place. This thread is being closed because it is a duplicate.
 
  


Closed Thread



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 03:49 PM
bash loop within a loop for mysql ops br8kwall Programming 10 04-30-2008 03:50 AM
bash, for loop, and arithmetic rmount Programming 13 05-23-2007 01:27 AM
Complex bash loop. hepburnenthorpe Linux - General 2 11-19-2006 09:42 AM
Bash for loop Genjix Programming 5 12-23-2004 02:56 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Desktop

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