LinuxQuestions.org
Review your favorite Linux distribution.
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 10-03-2007, 03:06 PM   #1
silverhand
LQ Newbie
 
Registered: Oct 2007
Posts: 5

Rep: Reputation: 0
help in display a sequence of number


I am doing a exercise for using for and while loop to perform from tw0 any variable by using command seq; but it is used for increasable number such as: 3 to 15 or 1 to 10..i was wonder like how about to perform from 15 to 3 or from 10 to 1; such as: using first and last flags...Plz help me to tide off this complex...Thanks for reading
 
Old 10-03-2007, 03:35 PM   #2
raskin
Senior Member
 
Registered: Sep 2005
Location: France
Distribution: approximately NixOS (http://nixos.org)
Posts: 1,900

Rep: Reputation: 69
Code:
seq 15 -1 3
 
Old 10-03-2007, 03:37 PM   #3
jozyba
Member
 
Registered: Sep 2007
Distribution: Debian Etch, Lenny, Lenny/Sid
Posts: 31

Rep: Reputation: 15
In man seq you see:
Quote:
seq [OPTION]... FIRST INCREMENT LAST
So if 'first' is 15, 'increment' is -1 and 'last' is 3 you get:
Code:
for x in $(seq 15 -1 3); do echo $x; done
likewise 10 to 1:
Code:
for x in $(seq 10 -1 1); do echo $x; done
Or if you're using bash and you want to decrease one at a time, you can use extended brace expansion:
Code:
for x in {15..1}; do echo $x; done
The advantage of using 'seq' is that you can decrement by a value other than one. For instance here we go from 15 to 3 in decrements of 5:
Code:
for x in $(seq 15 -5 3); do echo $x; done
 
Old 10-03-2007, 04:14 PM   #4
silverhand
LQ Newbie
 
Registered: Oct 2007
Posts: 5

Original Poster
Rep: Reputation: 0
thanks a lot guys...It got a very quick and nice lesson for my first step to bash script..thanks and cheers
 
  


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
ssh -X Proxy Display number Millenniumman Linux - Networking 0 04-09-2007 03:51 PM
how to not display the page number in latex naihe2010 General 1 10-31-2006 04:32 AM
How do you customize scripts' sequence number for different runlevels? Akhran Debian 2 03-25-2006 03:23 AM
udp + sequence number!!!!!! alaios Linux - Networking 1 07-27-2005 07:40 PM
Display line number n from a file doctorwebbox Linux - Newbie 2 01-05-2005 02:06 PM

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

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