LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Script to print range of numbers. First script (https://www.linuxquestions.org/questions/programming-9/script-to-print-range-of-numbers-first-script-843849/)

raige 11-12-2010 04:22 AM

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 (:

Nylex 11-12-2010 04:28 AM

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.

grail 11-15-2010 08:01 AM

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.


All times are GMT -5. The time now is 06:52 PM.