blob: c1953eec91aeff8c9b02878e8f64c6b0a8eecc89 [file] [log] [blame]
Chet Rameyac50fba2014-02-26 09:36:43 -05001#
2# Chet Ramey <chet.ramey@case.edu>
3#
4# Copyright 1995 Chester Ramey
5#
6# This program is free software; you can redistribute it and/or modify
7# it under the terms of the GNU General Public License as published by
8# the Free Software Foundation; either version 2, or (at your option)
9# any later version.
10#
11# TThis program is distributed in the hope that it will be useful,
12# but WITHOUT ANY WARRANTY; without even the implied warranty of
13# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14# GNU General Public License for more details.
15#
16# You should have received a copy of the GNU General Public License
17# along with this program; if not, write to the Free Software Foundation,
18# Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19
Jari Aaltoccc6cda1996-12-23 17:02:34 +000020# Generate a sequence from m to n, m defaults to 1.
21
22seq ()
23{
24 declare -i lo hi i # makes local
25 local _SEQ
26
27 case $# in
28 1) seq 1 "$1" ; return $? ;;
29 2) lo=$1 hi=$2
30 i=$lo _SEQ=""
31 while let "i <= hi"; do
32 _SEQ="${_SEQ}$i "
33 let i+=1
34 done
35 echo "${_SEQ# }"
36 return 0 ;;
37 *) echo seq: usage: seq [low] high 1>&2 ; return 2 ;;
38 esac
39}
40
41# like the APL `iota' function (or at least how I remember it :-)
42iota()
43{
44 case $# in
45 1) seq 1 "$1"; return $?;;
46 *) echo "iota: usage: iota high" 1>&2; return 2;;
47 esac
48}