Output redirection

Dan Bernstein brnstnd at kramden.acf.nyu.edu
Tue Oct 30 09:10:52 AEST 1990


In article <2933 at litchi.bbn.com> rsalz at bbn.com (Rich Salz) writes:
> In <15479 at hydra.gatech.EDU> gt0178a at prism.gatech.EDU (Jim Burns) writes:
> >to Abhay B. Joshi's c code. Let's assume a situation where you don't have
> >the source code. How would you synchronize output only thru shell
> >mechanisms?
> script(1).
> No doubt PTY can also do it.

No doubt, since there's a ``script'' clone included in the pty package.
Copy enclosed. Note that this version allows teeing to multiple files
(because it uses tee) and gives you a utmp entry so that talk/mail/etc
work (because it uses pty).

The simplest answer to Jim's question is to run ``pty foo'' rather than
``foo''. stdio in foo will see a tty and line-buffer output accordingly.

---Dan

#!/bin/sh
# Public domain.
case "$@" in
"") extra=typescript ;;
"-a") extra=typescript ;;
"-i") extra=typescript ;;
"-a -i") extra=typescript ;;
esac
echo "Script started, teeing $@" "$extra"
( echo 'Script started on '`date`;
  pty -s "$SHELL";
  echo 'Script done on '`date` ) | tee "$@" "$extra"



More information about the Comp.unix.shell mailing list