From owner-freebsd-questions Fri Aug 21 13:49:25 1998 Return-Path: Received: (from majordom@localhost) by hub.freebsd.org (8.8.8/8.8.8) id NAA28176 for freebsd-questions-outgoing; Fri, 21 Aug 1998 13:49:25 -0700 (PDT) (envelope-from owner-freebsd-questions@FreeBSD.ORG) Received: from marvin.ece.utexas.edu (marvin.ece.utexas.edu [128.83.52.151]) by hub.freebsd.org (8.8.8/8.8.8) with ESMTP id NAA28171 for ; Fri, 21 Aug 1998 13:49:24 -0700 (PDT) (envelope-from bgrayson@marvin.ece.utexas.edu) Received: (from bgrayson@localhost) by marvin.ece.utexas.edu (8.8.8/8.8.8) id PAA11390; Fri, 21 Aug 1998 15:48:37 -0500 (CDT) Message-ID: <19980821154837.A10756@marvin.ece.utexas.edu> Date: Fri, 21 Aug 1998 15:48:37 -0500 From: "Brian C. Grayson" To: Roman Katsnelson , "q's" Subject: Re: "clear" curiosity References: <35DDC102.CE22AD57@graphnet.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Mailer: Mutt 0.93.1i In-Reply-To: <35DDC102.CE22AD57@graphnet.com>; from Roman Katsnelson on Fri, Aug 21, 1998 at 02:48:34PM -0400 Sender: owner-freebsd-questions@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG On Fri, Aug 21, 1998 at 02:48:34PM -0400, Roman Katsnelson wrote: > Hi, > > I did 'cat clear' recently, and saw that all it said was > > exec tput clear > > I noticed that when I just type that in at the command line, the result > is entirely different -- it logs me out, clears the screen and gives a > new login prompt. I like this a lot better than the regular "exit" or > "Ctrl-D" thing because it clears the screen first. These are my two > questions: > > 1) Why are the results different between the same commands in a shell > script and at the command line? Look at execve(2) and exec(3) for info, but here's a slightly-accurate summary: The leading `exec' means, ``take the current process, and _replace_ it with tput.'' So if you type `exec ...' at the command line, the shell will no longer be running. To see this in action, do the following: Pop up two xterms. In one of them, type "echo $$" to get the shell PID, which I'll call . In the other xterm, do "ps ", and it will print your shell info. Now type "exec sleep 15" in the first xterm. Quickly do "ps " in the other xterm -- the PID is no longer your shell, it is the sleep process. Magic! :) After 15 seconds, the sleep will finish, and the xterm will close. If you want to simply clear the screen, skip the exec: 1. At a command line: you could type "tput clear" 2. In a shell script, without exiting the shell script: "tput clear" Hope this helps! Brian -- "sixty-six sevenths" -- Marty Ross, Math 211 exam To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-questions" in the body of the message