Show 1 to N on the terminal
By Joseph Russell •
I am looking for simple thing just, foo 8 will shows this:
1
2
3
4
5
6
7
8PS: I am looking just for command line. I know how to create that by using for on the bash
5 Answers
To print a sequence of number the command 'seq' is your friend
seq 8 3 {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 3 You can also use echo command with brace expansion
echo -e "\n"{1..8}
1
2
3
4
5
6
7
8If 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 2 Alternatively you can get it with simplest way as follows:
$ echo {1..8} | tr ' ' '\n'
1
2
3
4
5
6
7
8OR:
$ for ((i=1 ; i<=8 ; i++)) do echo $i ; done;
1
2
3
4
5
6
7
88 can be replaced by your 'N' positive integer!
You could use this simple for command,
$ for i in {1..8}; do echo $i; done
1
2
3
4
5
6
7
8Through awk,
$ awk 'BEGIN{for(i=1;i<=8;i++) {print i;}}'
1
2
3
4
5
6
7
8 5