LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
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 09-18-2010, 08:22 AM   #1
AsySyah
LQ Newbie
 
Registered: Sep 2010
Posts: 7

Rep: Reputation: 0
Linux command


how to convert this to for loop


can someone help me please

ctr=1
while test $ctr -le 20
do
tot=0
sctr=1
while test $sctr -le 4
do
echo -n "$ctr "
sctr=`expr $sctr + 1`
tot=`expr $tot + $ctr`
ctr=`expr $ctr + 1`
done
echo -n "$tot "
done

the output will show this
1 2 3 4 10 5 6 78 26 9 10 11 12 42 13 14 15 16 58 17 18 19 20 74
 
Old 09-18-2010, 08:41 AM   #2
MTK358
LQ 5k Club
 
Registered: Sep 2009
Posts: 6,443
Blog Entries: 3

Rep: Reputation: 721Reputation: 721Reputation: 721Reputation: 721Reputation: 721Reputation: 721Reputation: 721
Indentation and [code] tags, please.
 
Old 09-18-2010, 09:08 AM   #3
AsySyah
LQ Newbie
 
Registered: Sep 2010
Posts: 7

Original Poster
Rep: Reputation: 0
what do you mean by code tags...?? im using vi editor
 
Old 09-18-2010, 09:14 AM   #4
MTK358
LQ 5k Club
 
Registered: Sep 2009
Posts: 6,443
Blog Entries: 3

Rep: Reputation: 721Reputation: 721Reputation: 721Reputation: 721Reputation: 721Reputation: 721Reputation: 721
I'm talking about BBCode tags whaen posting code in the forums.

Without code tags:

int main()
{
printf("Hello, world!");
return 0;
}

With code tags:

Code:
int main()
{
    printf("Hello, world!");
    return 0;
}

Last edited by MTK358; 09-18-2010 at 09:17 AM.
 
Old 09-18-2010, 09:53 AM   #5
AsySyah
LQ Newbie
 
Registered: Sep 2010
Posts: 7

Original Poster
Rep: Reputation: 0
linux code tags.... in terminal
 
Old 09-18-2010, 09:55 AM   #6
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2392Reputation: 2392Reputation: 2392Reputation: 2392Reputation: 2392Reputation: 2392Reputation: 2392Reputation: 2392Reputation: 2392Reputation: 2392Reputation: 2392
Quote:
Originally Posted by AsySyah View Post
what do you mean by code tags...?? im using vi editor
Have a look here to see which are available and how to use them: BB Code List
 
Old 09-18-2010, 10:08 AM   #7
TobiSGD
Moderator
 
Registered: Dec 2009
Location: Germany
Distribution: Whatever fits the task best
Posts: 17,148
Blog Entries: 2

Rep: Reputation: 4860Reputation: 4860Reputation: 4860Reputation: 4860Reputation: 4860Reputation: 4860Reputation: 4860Reputation: 4860Reputation: 4860Reputation: 4860Reputation: 4860
Seems to me that we should do your homework for you.
 
Old 09-18-2010, 10:15 AM   #8
MTK358
LQ 5k Club
 
Registered: Sep 2009
Posts: 6,443
Blog Entries: 3

Rep: Reputation: 721Reputation: 721Reputation: 721Reputation: 721Reputation: 721Reputation: 721Reputation: 721
Quote:
Originally Posted by AsySyah View Post
linux code tags.... in terminal
They have nothing to do with Linux or terminals. They are bulletin board markup.
 
Old 09-18-2010, 10:20 AM   #9
AsySyah
LQ Newbie
 
Registered: Sep 2010
Posts: 7

Original Poster
Rep: Reputation: 0
yeah you right its actually my assignment... i`ve been trying it about more that 4 hours but still cant` get it i only can get the until result but cannot get the for result

Question 5
Write a shell script using for and until construct to display the following series:
1 2 3 4 10 5 6 78 26 9 10 11 12 42 13 14 15 16 58 17 18 19 20 74

Given script is using While Construct:
ctr=1
while test $ctr -le 20
do
tot=0
sctr=1
while test $sctr -le 4
do
echo -n "$ctr "
sctr=`expr $sctr + 1`
tot=`expr $tot + $ctr`
ctr=`expr $ctr + 1`
done
echo -n "$tot "
done
 
Old 09-18-2010, 10:24 AM   #10
MTK358
LQ 5k Club
 
Registered: Sep 2009
Posts: 6,443
Blog Entries: 3

Rep: Reputation: 721Reputation: 721Reputation: 721Reputation: 721Reputation: 721Reputation: 721Reputation: 721
1. It's against the rules for us to do your assignments for you. You can read more about bash loops.

2. Do you still not understand [code] tags? When posting, just type "[code]" right before your code, and "[/code]" right after your code. The forum will nicely format it and preserve the indentation.
 
Old 09-18-2010, 04:41 PM   #11
Mara
Moderator
 
Registered: Feb 2002
Location: Grenoble
Distribution: Debian
Posts: 9,683

Rep: Reputation: 219Reputation: 219Reputation: 219
Moved: This thread is more suitable in Programming and has been moved accordingly to help your thread/question get the exposure it deserves.

What is your problem with this task, exactly? First you need to find out the rule for the output. Then, what have you tried?
 
Old 09-19-2010, 10:01 PM   #12
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 9,641

Rep: Reputation: 2960Reputation: 2960Reputation: 2960Reputation: 2960Reputation: 2960Reputation: 2960Reputation: 2960Reputation: 2960Reputation: 2960Reputation: 2960Reputation: 2960
Well this might point you in the right direction:

http://tldp.org/LDP/abs/html/loops1.html
 
  


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
URGENT! Is there any command to get a history command lines and time in SUSE Linux.? igsoper Linux - Software 5 06-25-2009 03:14 AM
LXer: The Linux Command Shell For Beginners: Fear Not The Command Line! LXer Syndicated Linux News 0 12-22-2008 07:30 PM
Translating windows pscp command to linux scp command help robward Linux - General 2 01-17-2008 07:02 AM
Require Linux/Perl equivalent command for windows Command alix123 Programming 7 08-19-2005 03:23 AM
unix command to linux command leonidas Linux - General 1 09-10-2004 01:40 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 04:41 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration