if (isascii(c) && (isprint(c) || c=='\n' || c=='\t' || c==' ')) putchar(c); else if (!strip) printf("\\%03o", с);}3.8.61
waitfile.c/* waitfile: wait until file stops changing */#include <stdio.h>#include <sys/types.h>#include <sys/stat.h>char *progname;main(argc, argv) int argc; char *argv[];{ int fd; struct stat stbuf; time_t old_time = 0; progname = argv[0]; if (argc < 2) error("Usage: %s filename [cmd]", progname); if ((fd = open(argv[1], 0)) == -1) error("can't open %s", argv[1]); fstat(fd, &stbuf); while (stbuf.st_mtime != old_time) { old_time = stbuf.st_mtime; sleep(60); fstat(fd, &stbuf); } if (argc == 2) { /* copy file */ execlp("cat", "cat", argv[1], (char*)0); error("can't execute cat %s", argv[1]); } else { /* run process */ execvp(argv[2], &argv[2]); error("can't execute %s", argv[2]); } exit(0);}#include "error.c"3.8.62
watchfor# watchfor: watch for someone to log inPATH=/bin:/usr/bincase $# in0) echo 'Usage: watchfor person' 1>&2; exit 1esacuntil who | egrep "$1"do sleep 60done3.8.63
watchwho# watchwho: watch who logs in and outPATH=/bin:/usr/binnew=/tmp/wwho1.$$old=/tmp/wwho2.$$> $old # create an empty filewhile : # loop foreverdo who >$new diff $old $new mv $new $old sleep 60done | awk '/>/ { $1 = "in: "; print } /</ { $1 = "out: "; print }'3.8.64
which1# which cmd: which cmd in PATH is executed, version 1case $# in0) echo 'Usage: which command' 1>&2; exit 2esacfor i in `echo $PATH | sed 's/^:/.:/ s/::/:.:/g s/:$/:./ s/:/ /g'`do if test -f $i/$1 # use test -x if you can then echo $i/$1 exit 0 # found it fidoneexit 1 # not found3.8.65
which1.H# which cmd: which cmd in PATH is executed, version 1case $# in0) echo 'Usage: which command' 1>&2; exit 2esacfor i in `echo $PATH | sed 's/^:/.:/ s/::/:.:/g s/:$/:./ s/:/ /g'`do if test -f $i/$1 # use test -x if you can then echo $i/$1 exit 0 # found it fidoneexit 1 # not found@@@ Fri Oct 14 14:21:11 EDT 1983 original version3.8.66
which2# which cmd: which cmd in PATH is executed, final version