Ubuntu Forums ubuntu.com - launchpad.net - ubuntu help  

Go Back   Ubuntu Forums > The Ubuntu Forum Community > Other Community Discussions > Development & Programming > Programming Talk
Register Reset Password Forum Help Forum Council Search Today's Posts Mark Forums Read

Ubuntu 9.10 is out!!!

When downloading Ubuntu 9.10 please consider using bittorrent to get your copy of Ubuntu.

The Ubuntu Developers Summit for Lucid Lynx will be held the week of 16-Nov-2009 till 20-Nov-2009 in Dallas, TX USA. Visit the the Ubuntu wiki for more information about UDS and how to participate remotely.

Programming Talk
This forum is for all programming questions.
The questions do not have to be directly related to Ubuntu and any programming language is allowed.

 
Thread Tools Display Modes
Old February 21st, 2008   #1
phanther
Spilled the Beans
 
Join Date: Feb 2008
Location: Hyderabad, India
Beans: 14
Ubuntu 7.10 Gutsy Gibbon
Send a message via Yahoo to phanther
help regarding for loop syntax in ubuntu 7.10

hi,
i am a novice regarding linux.actually i am working on shell scripting in ubuntu 7.1.i am facing a lot of trouble with the "for loop" statement.
In which ever the format i am giving i am getting the same error as "bad for loop variable".

please help me with the syntax of for loop, if possible please provide me with a valid example which is working in the 7.1 version of ubuntu so that i can try it out.

thanx in advance
phanther is offline   Reply With Quote
Old February 21st, 2008   #2
LaRoza
Day Old Decaf
 
Join Date: Apr 2007
Beans: 14,805
Send a message via AIM to LaRoza Send a message via MSN to LaRoza Send a message via Yahoo to LaRoza
Re: help regarding for loop syntax in ubuntu 7.10

Quote:
Originally Posted by phanther View Post
hi,
i am a novice regarding linux.actually i am working on shell scripting in ubuntu 7.1.i am facing a lot of trouble with the "for loop" statement.
In which ever the format i am giving i am getting the same error as "bad for loop variable".

please help me with the syntax of for loop, if possible please provide me with a valid example which is working in the 7.1 version of ubuntu so that i can try it out.

thanx in advance
http://www.faqs.org/docs/abs/HTML/loops.html
LaRoza is offline   Reply With Quote
Old February 21st, 2008   #3
phanther
Spilled the Beans
 
Join Date: Feb 2008
Location: Hyderabad, India
Beans: 14
Ubuntu 7.10 Gutsy Gibbon
Send a message via Yahoo to phanther
Re: help regarding for loop syntax in ubuntu 7.10

hey thanx for the reply, i found the syntax i was looking for in the html link u have provided, but i have already used that syntax and i am still facing the same problem.let me clearly describe what is it that i am trying to do.the syntax goes like this:

#!/bin/bash

k=10

for ((i=1; i <= k; i++))
do
echo -n "$i "
done

the error that i am getting is "Bad for loop variable".

thnx again and i'll be looking forward for a reply
phanther is offline   Reply With Quote
Old February 21st, 2008   #4
darsu
Just Give Me the Beans!
 
Join Date: Mar 2006
Beans: 64
Kubuntu 8.10 Intrepid Ibex
Re: help regarding for loop syntax in ubuntu 7.10

Odd. I tried that; it works with bash but not with sh.


See here: http://ubuntuforums.org/archive/index.php/t-442794.html
darsu is offline   Reply With Quote
Old February 21st, 2008   #5
phanther
Spilled the Beans
 
Join Date: Feb 2008
Location: Hyderabad, India
Beans: 14
Ubuntu 7.10 Gutsy Gibbon
Send a message via Yahoo to phanther
Re: help regarding for loop syntax in ubuntu 7.10

@darsu

can u tell me how did u run it, n did u give the same amt of spaces as i hav in the above thread.

if so can u pls tell me wat could be the problem. i've checked the shell i'm workin in, its bash n not sh.so i still cant figure out the mistake.infact i am unable to run any script related to "for" loop
phanther is offline   Reply With Quote
Old February 21st, 2008   #6
darsu
Just Give Me the Beans!
 
Join Date: Mar 2006
Beans: 64
Kubuntu 8.10 Intrepid Ibex
Re: help regarding for loop syntax in ubuntu 7.10

I cut and pasted your code into something.sh and executed it with "bash ./something.sh" and "sh ./something.sh".
darsu is offline   Reply With Quote
Old February 21st, 2008   #7
LaRoza
Day Old Decaf
 
Join Date: Apr 2007
Beans: 14,805
Send a message via AIM to LaRoza Send a message via MSN to LaRoza Send a message via Yahoo to LaRoza
Re: help regarding for loop syntax in ubuntu 7.10

Note that the default shell in Ubuntu is dash, not bash.

http://en.wikipedia.org/wiki/Debian_Almquist_shell

Last edited by LaRoza; February 21st, 2008 at 07:02 PM..
LaRoza is offline   Reply With Quote
Old February 22nd, 2008   #8
phanther
Spilled the Beans
 
Join Date: Feb 2008
Location: Hyderabad, India
Beans: 14
Ubuntu 7.10 Gutsy Gibbon
Send a message via Yahoo to phanther
Re: help regarding for loop syntax in ubuntu 7.10

@darsu & LaRoza

thank you very much, i got the answer from u both.

i made the right choice of asking u darsu about the execution thing.i've been executing it using the second way i.e using "sh".i had a wrong notion while executing it.i got the answers n its clear to me now.

Thanks LaRoza for providing the information regarding the shells and loops.

Now i have another doubt regarding the the above program, it is:

what will this piece of code do: "#!/bin/bash"
phanther is offline   Reply With Quote
Old February 22nd, 2008   #9
Zwack
Way Too Much Ubuntu
 
Join Date: Nov 2004
Location: Portland, Or, USA
Beans: 288
Ubuntu 8.10 Intrepid Ibex
Re: help regarding for loop syntax in ubuntu 7.10

Quote:
Originally Posted by phanther View Post
Now i have another doubt regarding the the above program, it is:

what will this piece of code do: "#!/bin/bash"
That depends on where it is in the file...

If the file is executable and that is the very first line (i.e. the first two characters are #!) then it will cause the script when run to use /bin/bash as the interpreter.

Otherwise it will be an interesting comment...

Z.
Zwack is offline   Reply With Quote
Old February 22nd, 2008   #10
ghostdog74
Iced Blended Vanilla Crème Ubuntu
 
Join Date: Sep 2006
Beans: 2,715
Re: help regarding for loop syntax in ubuntu 7.10

please read here, and also the whole document.
ghostdog74 is offline   Reply With Quote

Bookmarks

Thread Tools
Display Modes

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

Forum Jump


All times are GMT -4. The time now is 11:06 PM.


vBulletin ©2000 - 2009, Jelsoft Enterprises Ltd. Ubuntu Logo, Ubuntu and Canonical © Canonical Ltd. Tango Icons © Tango Desktop Project. bilberry