![]() |
ubuntu.com - launchpad.net - ubuntu help
|
|
|||||||
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 |
|
|
|
|
#1 |
|
Spilled the Beans
![]() |
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 |
|
|
|
|
|
#2 | |
|
Day Old Decaf
![]() |
Re: help regarding for loop syntax in ubuntu 7.10
Quote:
|
|
|
|
|
|
|
#3 |
|
Spilled the Beans
![]() |
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 |
|
|
|
|
|
#4 |
|
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 |
|
|
|
|
|
#5 |
|
Spilled the Beans
![]() |
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 |
|
|
|
|
|
#6 |
|
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".
|
|
|
|
|
|
#7 |
|
Day Old Decaf
![]() |
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.. |
|
|
|
|
|
#8 |
|
Spilled the Beans
![]() |
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" |
|
|
|
|
|
#9 | |
|
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:
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. |
|
|
|
|
|
|
#10 |
|
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.
__________________
Python tutorial |Learn Bash scripting|Effective AWK|A handful of Awk|Perl|File Renamer |
|
|
|
| Bookmarks |
| Thread Tools | |
| Display Modes | |
|
|