rc-list - mailing list for the rc(1) shell
 help / color / mirror / Atom feed
* Re:  Speaking of counting...
@ 1997-05-02  3:30 Rich Salz
  1997-05-02 14:51 ` John Robert LoVerso
  0 siblings, 1 reply; 9+ messages in thread
From: Rich Salz @ 1997-05-02  3:30 UTC (permalink / raw)
  To: culliton, rc

I remember an old bsd4.2 "contrib" command called jot that did this
kind of thing.


^ permalink raw reply	[flat|nested] 9+ messages in thread
* Re: Speaking of counting...
@ 1997-05-03 12:43 rsc
  0 siblings, 0 replies; 9+ messages in thread
From: rsc @ 1997-05-03 12:43 UTC (permalink / raw)
  To: culliton, rc

#!/bin/rc

first=0
last=0
incr=0
switch($#*) {
case 0
	echo 'Usage: $0 [first [incr]] last'
	exit 1
case 1
	last=$1
case 2
	first=$1
	last=$2
case 3
	first=$1
	incr=$2
	last=$3
}

awk -v 'first='$first -v 'last='$last -v 'incr='$incr 'BEGIN{
	if(incr == 0)
		incr = 1;
	if(first == 0)
		first = 1;
	for(i = first; i <= last; i += incr)
		print i;
}'

------ forwarded message follows ------

From hawkwind.utcs.toronto.edu!rc-owner Fri May  2 19:49:49 EDT 1997
Received: from corona.research.att.com by plan9; Fri May  2 19:49:49 EDT 1997
Received: from research.att.com (research.research.att.com [135.205.32.20]) by corona.research.att.com (8.7.5/8.7) with SMTP id TAA29692 for <rsc@corona.research.att.com>; Fri, 2 May 1997 19:50:01 -0400 (EDT)
Received: from hawkwind.utcs.utoronto.ca ([128.100.102.51]) by research; Fri May  2 19:48:54 EDT 1997
Received: from mail.clark.net ([168.143.0.10]) by hawkwind.utcs.utoronto.ca with SMTP id <24662>; Fri, 2 May 1997 19:45:47 -0400
Received: from clark.net (culliton@explorer.clark.net [168.143.0.7]) by mail.clark.net (8.8.5/8.6.5) with ESMTP id SAA17772; Fri, 2 May 1997 18:08:51 -0400 (EDT)
From: Tom Culliton <clark.net!culliton>
Received: (from culliton@localhost) by clark.net (8.8.5/8.7.1) id SAA16770; Fri, 2 May 1997 18:09:14 -0400 (EDT)
Date: 	Fri, 2 May 1997 18:09:14 -0400
Message-Id: <199705022209.SAA16770@clark.net>
To: hawkwind.utcs.toronto.edu!rc
Cc: LoVerso.Southborough.MA.US!john, osf.org!rsalz
Subject: Re: Speaking of counting...

So far jot and seq have been mentioned, (every machine I have available
says "jot not found" though... and ditto seq) but no specifics,

I have been accused of wanting to reinventing the wheel, (exactly what
I was trying to avoid)

Scott has shared some perl code, (Euw! The evil anit-rc!) ;-) (Thank
you.)

I swear I've seen this in rc/awk before...


^ permalink raw reply	[flat|nested] 9+ messages in thread
* Re: Speaking of counting...
@ 1997-05-03  7:57 Byron Rakitzis
  0 siblings, 0 replies; 9+ messages in thread
From: Byron Rakitzis @ 1997-05-03  7:57 UTC (permalink / raw)
  To: culliton, rc; +Cc: john, rsalz

Here's my version of seq:

#!/bin/rc
switch ($#*) {
case 1
        lo=1; hi=$1; incr=1
case 2
        lo=$1; hi=$2; incr=1
case 3
        lo=$1; hi=$2; incr=$3;
case *
        echo 'usage: seq [ lo ] hi [ incr ]' >[1=2]; exit 1
}

awk </dev/null 'END {
        if ('$incr' > 0) {
                for (i = '$lo'; i <= '$hi'; i += '$incr')
                        print i
        } else {
                for (i = '$lo'; i >= '$hi'; i += '$incr')
                        print i
        }
}'

It's possible that I got this from Paul Haahr (or someone else for
that matter --- I know my input-less awk scripts do all their work
in the BEGIN clause), and I don't have my plan9 manuals with me in
Europe so I have no idea if it matches up with plan9 seq.



^ permalink raw reply	[flat|nested] 9+ messages in thread
* Re: Speaking of counting...
@ 1997-05-02 22:09 Tom Culliton
  0 siblings, 0 replies; 9+ messages in thread
From: Tom Culliton @ 1997-05-02 22:09 UTC (permalink / raw)
  To: rc; +Cc: john, rsalz

So far jot and seq have been mentioned, (every machine I have available
says "jot not found" though... and ditto seq) but no specifics,

I have been accused of wanting to reinventing the wheel, (exactly what
I was trying to avoid)

Scott has shared some perl code, (Euw! The evil anit-rc!) ;-) (Thank
you.)

I swear I've seen this in rc/awk before...


^ permalink raw reply	[flat|nested] 9+ messages in thread
* Speaking of counting...
@ 1997-05-01 21:40 Tom Culliton
  1997-05-02  1:26 ` Scott Schwartz
  1997-05-02  2:44 ` Charles M. Hannum
  0 siblings, 2 replies; 9+ messages in thread
From: Tom Culliton @ 1997-05-01 21:40 UTC (permalink / raw)
  To: rc

Does anyone have a nice little generic range function for rc?  The
type of thing that lets generate a list something like the indices
from a fortran or basic for statement.  (I'm actually modelling this
after the one in python.)

1 argument means	for (i = 0; i < $1; i += 1)
2 arguments mean	for (i = $1; i < $2; i += 1)
3 arguments mean	for (i = $1;
			     ($3 > 0 && i < $2) || ($3 > 0 && i > $2;
			     i += $3)

For example...

	# echo 99 down to but not including 0
	for (i in `{range 99 0 -1}) echo $i
	# echo 0 up to but not including 10
	for (i in `{range 0 10}) echo $i
	# echo 0 up to but not including 10 stepping 2
	for (i in `{range 0 10 2}) echo $i
	# echo 0 up to but not including 10
	for (i in `{range 10}) echo $i

I could whip something up using awk, but someone must already have one!

Tom


^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~1997-05-03 18:35 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1997-05-02  3:30 Speaking of counting Rich Salz
1997-05-02 14:51 ` John Robert LoVerso
  -- strict thread matches above, loose matches on Subject: below --
1997-05-03 12:43 rsc
1997-05-03  7:57 Byron Rakitzis
1997-05-02 22:09 Tom Culliton
1997-05-01 21:40 Tom Culliton
1997-05-02  1:26 ` Scott Schwartz
1997-05-02  2:44 ` Charles M. Hannum
1997-05-02  5:52   ` Scott Schwartz

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).