Date: Fri, 21 Aug 1998 15:48:37 -0500 From: "Brian C. Grayson" <bgrayson@marvin.ece.utexas.edu> To: Roman Katsnelson <romank@graphnet.com>, "q's" <freebsd-questions@FreeBSD.ORG> Subject: Re: "clear" curiosity Message-ID: <19980821154837.A10756@marvin.ece.utexas.edu> In-Reply-To: <35DDC102.CE22AD57@graphnet.com>; from Roman Katsnelson on Fri, Aug 21, 1998 at 02:48:34PM -0400 References: <35DDC102.CE22AD57@graphnet.com>
next in thread | previous in thread | raw e-mail | index | archive | help
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 <PID>. In the other xterm, do "ps <PID>", and it will print your shell info. Now type "exec sleep 15" in the first xterm. Quickly do "ps <PID>" 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
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?19980821154837.A10756>