seq for OS X

It has always irked me that OS X doesn’t have the seq command (I am easily irked). Brian Peterson’s old e-mail Re: seq from core utils has it, but the link to sh-utils doesn’t work any more, since the project has been archived. Here’s the new link: http://ftp.gnu.org/old-gnu/sh-utils/. Compile it as Brian suggested, and all will be well.

$ seq 1 12
1
2
3
4
5
6
7
8
9
10
11
12

Joy!
(at least 99% of you will be mystified why anyone would want this.)

Tags: , ,

11 Responses to “seq for OS X”

  1. jasper Says:
    .. or install macports and do a
    $ sudo port install coreutils
    which will get you a gseq:
    $ gseq 1 12
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
  2. scruss Says:
    Yeah, but it’s called ’seq’ in all the scripts I have, and it wouldn’t be worth me having macports for just one command.
  3. markus Says:
    Hi, agreed, it bothers me too…. so much did i want this functionality without needing to do darwin ports … and having seen your recent post on this topic, i’ve just knocked together a 2 min bash script to add this functionality without actually installing anything,

    i just made this script and called it /usr/bin/seq
    chmod +x /usr/bin/seq
    and i’m good to go..

    … i also hope this posts ok…. i have a feeling it may get filtered by the forum… maybe you can figure it out again

    #!/bin/bash
    # marks rude seq replacement for osx.

    if [ $# -eq 2 ]
    then
    let from=”$1″;
    let to=”$2″;
    elif [ $# -eq 1 ]
    then
    let from=”0″;
    let to=”$1″;
    else
    echo “USAGE: seq [num from] [num to]”
    exit 1;
    fi

    while [ $from -lt $to ]
    do
    printf “$from “;
    from=$[$from+1]
    done
    printf “$from “;

  4. Robert Borkowski Says:
    sudo ln -s /opt/local/bin/gseq /opt/local/bin/seq

    :-)

  5. scruss Says:
    see the second comment, Robert. And /opt is a crime against nature!
  6. scruss Says:
    Oh, and there’s also always ‘jot’, seq’s weird hippie cousin which is installed by default: http://www.nevdull.com/2007/09/24/gnu-seqs-cousin-on-freebsd-is-jot/

    Nice try with that shell, Markus. It would work for maybe 80% of uses, but would fail for the rest.

  7. scruss Says:
    Playing with jot a bit (I’m on a train), I rather like it. What jot can do in one command

    jot -w %02x 255 0

    (printing hexadecimal numbers 00 .. ff) seq needs a composite command:

    seq 0 255 | xargs -n1 printf “%02x\n”

    neat!

  8. prof_k Says:
    Just an improvement of the bash script (which doesn’t yet work properly for jot with an increment). Further improvement is welcome !

    #!/bin/bash
    # marks rude seq replacement for osx.

    # set -ex

    method=1

    case ${method} in
    1)
    # a simple bash script:
    if [ $# -eq 2 ]
    then
    let from=”$1″;
    let to=”$2″;
    let step=1
    elif [ $# -eq 1 ]
    then
    let from=”0″;
    let to=”$1″;
    let step=1
    elif [ $# -eq 3 ]
    then
    let from=”$1″
    let to=”$3″
    let step=”$2″
    else
    echo “USAGE: seq [num from] [[num step]] [num to]”
    exit 1;
    fi

    while [ $from -le $to ]
    do
    printf “$from \n”;
    from=$[$from+$step]
    done
    ;;
    2)
    # Using the jot command:

    if [ $# -eq 2 ]
    then
    let numstep=`expr ‘(’ $2 - $1 + 1 ‘)’ `
    jot $numstep $1 $2
    elif [ $# -eq 3 ]
    then
    let numstep=`expr ‘(’ $3 - $1 + 1 ‘)’ / $2 `
    let to=`expr $3 - ‘(’ ‘(’ $3 - $1 + 1 ‘)’ % $numstep ‘)’ `
    jot ${numstep} $1 $to
    else
    echo “USAGE: seq [num from] [[num step]] [num to]”
    exit 1;
    fi
    ;;
    esac

  9. scruss Says:
    thanks. Wordpress may have munged the quotes - I hate when it does that.
  10. someone Says:
    Thanks, but the seq builds are for PPC and not for intel.

    but the macports idea is good!

  11. scruss Says:
    erm, but the sh-utils build trick is platform-neutral.

Leave a Reply