Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I am looking for simple thing just, foo 8 will shows this:

1
2
3
4
5
6
7
8

PS: I am looking just for command line. I know how to create that by using for on the bash

share|improve this question
    
Are you saying you know the seq command (or brace expansion {1..N}) and are looking for something else? –  muru Jul 25 at 12:04
    
No I say I know how show them via wrting a bash file. But I do not know there is 'seq' command. –  lion Jul 25 at 12:06
    
@muru anyway thanks for help –  lion Jul 25 at 12:32

5 Answers 5

up vote 33 down vote accepted

To print a sequence of number the command 'seq' is your friend

seq 8
share|improve this answer
2  
Also, seq 5 10 prints 5 6 7 8 9 10, and seq 8 16 2 prints 8 10 12 14 16 (increments by 2 each step) –  professorfish Jul 25 at 16:47
6  
@professorfish FOr the second, it's seq 8 2 16, with the increment between first and last. seq 8 16 2 prints nothing. (I always get it wrong too.) –  Jefromi Jul 26 at 0:41
    
seq is widely available in many Unices, and is part of coreutils in Linux, but it's not POSIX and not portable. –  200_success Jul 26 at 16:56
    
Welcome to AskUbuntu! –  No Time Aug 21 at 5:05

{1..8} will give you a simple argument range in Bash.

If you need that line by line, I'd suggest feeding that to something like printf:

$ printf '%d\n' {1..8}
1
2
3
4
5
6
7
8
share|improve this answer
    
in here if 8 is a parameter. what I should write ? I mean: printf '%d\n' {0..a} ? thanks. –  lion Aug 14 at 14:19
    
I try $a and ${a} and ... –  lion Aug 14 at 14:26
1  
@lion You have to re-evaluate the line because Bash won't expand. It becomes something like n=5; printf '%d\n' $(eval echo {0..$n}) –  Oli Aug 14 at 14:37
    
thank you very much –  lion Aug 14 at 14:38

You can also use echo command with brace expansion

echo -e "\n"{1..8}

1 
2 
3 
4 
5 
6 
7 
8

If you don't want the initial newline, you can use one of the below commands.

echo -e "\n"{1..8}|tail -n8

echo -e "\n"{1..8}|grep .

echo -e "\n"{1..8}|grep [0-9]

echo -e "\n"{1..8}|sed 1d
share|improve this answer
    
Just a heads up, the output starts with a newline, which may need to be trimmed out (perhaps with tail?) if you use the generated list of numbers in a script. –  IQAndreas Jul 27 at 4:40
1  
@IQAndreas I have made a edit and added all commands I could think of to remove the newline. –  Registered User Jul 27 at 12:34

Alternatively you can get it with simplest way as follows:

$ echo {1..8} | tr ' ' '\n'
1
2
3
4
5
6
7
8

OR:

$ for ((i=1 ; i<=8 ; i++)) do echo $i ; done;
1
2
3
4
5
6
7
8

8 can be replaced by your 'N' positive integer!

share|improve this answer

You could use this simple for command,

$ for i in {1..8}; do echo $i; done
1
2
3
4
5
6
7
8

Through awk,

$ awk 'BEGIN{for(i=1;i<=8;i++) {print i;}}'
1
2
3
4
5
6
7
8
share|improve this answer
    
The OP specified: I know how to create that by for on the bash. Use while to bring something new. –  Radu Rădeanu Jul 26 at 12:01
    
@RaduRădeanu added awk command. –  Avinash Raj Jul 26 at 16:54
1  
It is still using for :) –  Radu Rădeanu Jul 26 at 17:00
    
OMG, i think he doesn't mean the awk for command. –  Avinash Raj Jul 26 at 17:01
    
And also I think he doesn't mean such a long command... WOE to use bla bla bla ... print i ... bla bla when you can only use only printf '%d\n' {1..8}? –  Radu Rădeanu Jul 26 at 17:16

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.