shell

Printing sequential numbers in BSD

In Linux, the seq command is pretty useful in some scripts, because it prints a sequence of numbers:

$ seq 1 5
1
2
3
4
5

It is usually used in for loops:

for i in `seq 1 5`;
do
    ...
done

But this command is not included in BSD-like OSes. It is contained in the sh-utils, so one option is downloading and compiling it. But I prefer using the commands that come by default with the OS, for portability. In the BSD case, I found the jot command that prints sequential or random data. The following example shows the seq behaviour with jot.

$ jot 5
1
2
3
4
5

Other example where jot shows the integers between 13 and 17: the first argument (5) represents how many values will be shown. The second argument (13) is the number to start counting at:

$ jot 5 13
13
14
15
16
17

speak up

Add your comment below, or trackback from your own site.

Subscribe to these comments.

Be nice. Keep it clean. Stay on topic. No spam.

You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

*Required Fields