Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!tut.cis.ohio-state.edu!ucbvax!bloom-beacon!adam.pika.mit.edu!scs From: scs@adam.pika.mit.edu (Steve Summit) Newsgroups: comp.unix.wizards Subject: shell file descriptor programming (was: Unlinked temp files) Message-ID: <10944@bloom-beacon.MIT.EDU> Date: 29 Apr 89 05:39:13 GMT References: <871@marvin.Solbourne.COM> <1015@philmds.UUCP> Sender: daemon@bloom-beacon.MIT.EDU Reply-To: scs@adam.pika.mit.edu (Steve Summit) Lines: 32 In article <1015@philmds.UUCP> leo@philmds.UUCP (Leo de Wit) writes: >The shell has no means to rewind that I know of; however, a simple >one-liner will do the trick (add error checking of your fancy): >----- rewind.c: >main(argc,argv) int argc; char **argv; { lseek(atoi(argv[1]),0L,0); } Ah, yes, a great old trick, impresses the hell out of your friends, guaranteed to break the ice at parties, but you should be more general and write lseek(1) instead of rewind(1S): extern long int atol(); main(argc, argv) int argc; char *argv[]; {lseek(atoi(argv[1]), atol(argv[2]), atoi(argv[3]);} or, further eschewing compiled code, ci <<% lseek($1, $2L, $3); % (assuming ci is your friendly neighborhood C interpreter, not RCS checkin). Of course, the other great benefit of playing with file descriptors with 4> and 5< and the like is that it lets us stick it to the ever-increasing ranks of csh users :-). Steve Summit scs@adam.pika.mit.edu P.S. Don't try lseek(0, -1L, 0) from your login shell (but you will...).