Xref: utzoo comp.unix.admin:530 comp.unix.questions:26917 comp.unix.shell:902 Path: utzoo!attcan!uunet!wuarchive!udel!rochester!kodak!ispd-newsserver!weimer From: weimer@ssd.kodak.com (Gary Weimer) Newsgroups: comp.unix.admin,comp.unix.questions,comp.unix.shell Subject: Re: telnet in a shell script Message-ID: <1990Nov14.162106.25074@ssd.kodak.com> Date: 14 Nov 90 16:21:06 GMT References: <3886@male.EBay.Sun.COM> <8026@muffin.cme.nist.gov> <7006:Nov1408:13:3290@kramden.acf.nyu.edu> Sender: news@ssd.kodak.com Organization: Eastman Kodak Lines: 13 In article <7006:Nov1408:13:3290@kramden.acf.nyu.edu> brnstnd@kramden.acf.nyu.edu (Dan Bernstein) writes: >Here waitfor is a dumb program along the lines of > > extern char *malloc(); main(argc,argv) int argc; char *argv[]; { > int len; char *s; int pos; char ch; int f; int p; if (!argv[1]) > exit(1); len = strlen(argv[1]); if (!(s = malloc(len))) exit(2); > pos = 0; f = 0; while (read(0,&ch,1) == 1) { if (write(2,&ch,1) != 1) > exit(3); if (ch) { s[pos] = ch; pos++; if (pos == len) { f = 1; > pos = 0; } if (f && (ch == argv[1][len - 1])) { for (p = 1; > s[(pos + p) % len] == argv[1][p];p++) ; if (!argv[1][p]) exit(0); > } } } exit(4); } Niceformatingyougotthere :-)