Article View: comp.unix.shell
Article #1865Re: A question on csh/sh.
From: Dan Bernstein
Date: Fri, 30 Nov 1990 10:40
Date: Fri, 30 Nov 1990 10:40
37 lines
1749 bytes
1749 bytes
In article <~0_^-Z^@rpi.edu> fitz@mml0.meche.rpi.edu (Brian Fitzgerald) writes:
> >password change. Basically I want to do:
> > myshscript oldpasswd newpasswd
> IMHO, you might want to reconsider this idea for (at least) two reasons.
Yes, it's a bad idea, but the technical question still stands.
Quick 'n' easy, but a kludge:
#!/bin/sh
(sleep 5; echo $1; sleep 5; echo $2; sleep 5; echo $2) | pty passwd
Properly synchronized, using named pipes:
#!/bin/sh
/etc/mknod out.$$ p;exec 2>&1
( exec 4<out.$$; rm -f out.$$
<&4 waitfor 'word: '
echo $1
<&4 waitfor 'word: '
echo $2
<&4 waitfor '(again): '
echo $2
) | pty passwd > out.$$
Here waitfor is that same text search utility as last time:
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); }
---Dan
Technical Details
Message-ID:
<11572:Nov3010:40:1990@kramden.acf.nyu.edu>Path:
arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!usc!julius.cs.uiuc.edu!psuvax1!hsdndev!cmcl2!kramden.acf.nyu.edu!brnstndReferences:
<70.2743fe39@vax1.cc.lehigh.edu> <~0_^-Z^@rpi.edu>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!usc!julius.cs.uiuc.edu!psuvax1!hsdndev!cmcl2!kramden.acf.nyu.edu!brnstnd From: brnstnd@kramden.acf.nyu.edu (Dan Bernstein) Newsgroups: comp.unix.shell Subject: Re: A question on csh/sh. Summary: some answers Message-ID: <11572:Nov3010:40:1990@kramden.acf.nyu.edu> Date: 30 Nov 90 10:40:19 GMT References: <70.2743fe39@vax1.cc.lehigh.edu> <~0_^-Z^@rpi.edu> Organization: IR Lines: 37