LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
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 11-12-2010, 04:22 AM   #1
raige
LQ Newbie
 
Registered: Nov 2010
Posts: 2

Rep: Reputation: 0
Script to print range of numbers. First script


Hi, so i'm new to whole linux enviroment and am trying to write script for first time and after hour of searching and trying to figure this out on my own i decided to turn to you professionals.

I need to write script wich will print range of numbers for me.
for example if the script file name is file1
i need the kind of script that when i type ./file1 x y it will print numbers from x to y

what i tried for example is seq cmd but i dont know how i can make the first and last number as variables/parameter that i can type in as x and y

hope someone understood my rambling (:
 
Old 11-12-2010, 04:28 AM   #2
Nylex
LQ Addict
 
Registered: Jul 2003
Location: London, UK
Distribution: Slackware
Posts: 7,464

Rep: Reputation: Disabled
Assuming you're using Bash, the first command line argument to the script is stored in variable $1, the second in $2 and so on, so you can use those in your call to seq.

Edit: if you're not writing in Bash, then tell us which language you are using.

Last edited by Nylex; 11-13-2010 at 06:46 AM.
 
Old 11-15-2010, 08:01 AM   #3
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 10,007

Rep: Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191
Also if in bash you could make it a simple for loop as you would in any other language and using passed in variables as outlined by Nylex.
 
  


Reply



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
[SOLVED] Script to add up numbers in textfile philipz Programming 3 05-20-2010 08:38 AM
error in script for adding two numbers krap Linux - Newbie 3 08-09-2008 01:05 PM
[Sh script] "xpdf -cmd", How to print pdf with a script ? frenchn00b Linux - Software 1 10-02-2007 04:44 PM
command or shell script to print line range from file minil Programming 3 12-28-2005 08:05 AM
massive numbers of email accounts and script js_530 Linux - General 4 07-24-2003 01:42 PM

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

All times are GMT -5. The time now is 11:29 AM.

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