Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!uunet!husc6!necntc!ima!minya!jc From: jc@minya.UUCP (John Chambers) Newsgroups: comp.unix.wizards Subject: Redirecting shell output. Message-ID: <289@minya.UUCP> Date: Sun, 18-Oct-87 10:51:49 EDT Article-I.D.: minya.289 Posted: Sun Oct 18 10:51:49 1987 Date-Received: Mon, 19-Oct-87 00:08:15 EDT Organization: home Lines: 39 Hi, folks. Here's my shell puzzle of the day. We all learn in our first hour of Unix lessons how to redirect input and output of any command that is started by a shell. What I'd like to know is: Is there a "right" way to tell the shell to redirect the output of ALL subsequent commands to a file? My motivation is as follows. Like some of you, I have written scripts that aren't, let's say, totally perfect the first time. Something really hard to debug is a script that works fine when I run it, but doesn't work so fine when someone else (like cron, maybe) runs it. What I'd like to do is to arrange it so that the program redirects its own output to an "audit trail" for my perusal. I don't want to bother the poor user with all the garbage output; I'd rather have it done quietly, with no fuss or bother. For C programs, this is easy: close(1); open("/aud/fubar",2); close(2); dup(1); for instance. For scripts, it's not so easy. What I find myself doing a lot is having one script, "foo", that looks like: exec bar >/aud/foo 2>&1 with the real work in the "bar" script. This works just fine, but it seems a rather clumsy approach. I have two scripts where one would do, the "foo" script occupies a whole 1K disk block (and an inode and a directory entry) unnecessarily, and the kernel is bothered with a totally unneeded exec. What I'd like is to write the "bar" script so that it starts with something equivalent to the above four lines of C. But I can't find anything in the sh(1) pages, or in the shell teaching documents, that explains how to do file opens and closes in the shell language. Any hints? Or is this just a deficiency in the language that I'll have to learn to live with? I mean, it's not a big deal to have one script exec another. It just seems like a silly kludge that wastes my and the machine's time and makes the code look awkward. That's unaesthetic. -- John Chambers <{adelie,ima,maynard,mit-eddie}!minya!{jc,root}> (617/484-6393)