From owner-freebsd-questions Fri Aug 21 13:26:22 1998 Return-Path: Received: (from majordom@localhost) by hub.freebsd.org (8.8.8/8.8.8) id NAA25396 for freebsd-questions-outgoing; Fri, 21 Aug 1998 13:26:22 -0700 (PDT) (envelope-from owner-freebsd-questions@FreeBSD.ORG) Received: from elvis.vnet.net (elvis.vnet.net [166.82.1.5]) by hub.freebsd.org (8.8.8/8.8.8) with ESMTP id NAA25389 for ; Fri, 21 Aug 1998 13:26:16 -0700 (PDT) (envelope-from rivers@dignus.com) Received: from dignus.com (ponds.vnet.net [166.82.177.48]) by elvis.vnet.net (8.8.8/8.8.4) with ESMTP id QAA27162; Fri, 21 Aug 1998 16:25:31 -0400 (EDT) Received: from lakes.dignus.com (lakes [10.0.0.3]) by dignus.com (8.8.8/8.8.5) with ESMTP id RAA13087; Fri, 21 Aug 1998 17:01:05 -0400 (EDT) Received: (from rivers@localhost) by lakes.dignus.com (8.8.8/8.6.9) id QAA02219; Fri, 21 Aug 1998 16:29:23 -0400 (EDT) Date: Fri, 21 Aug 1998 16:29:23 -0400 (EDT) From: Thomas David Rivers Message-Id: <199808212029.QAA02219@lakes.dignus.com> To: freebsd-questions@FreeBSD.ORG, romank@graphnet.com Subject: Re: "clear" curiosity In-Reply-To: <35DDC102.CE22AD57@graphnet.com> Sender: owner-freebsd-questions@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG > > 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? > and > 2) How can I write a shell script that does the same thing? (I tried, > but, of course, it did exactly what 'clear' does). > > Thanks for any ideas, Recall what 'exec' means to the shell. It means to "replace" the current process (the shell) with the named one. So, your shell isn't running anymore, the tput program is. When the tput program ends; you are logged off. Now, consider what this does for a shell script. Recall that executing a script actually starts up another shell (unless you use exec to avoid that.) So, when you have this in a shell script and execute that script... the sub-shell exec's tput; which ends and returns back to your original shell. From the 'sh' man page: exec [command arg ...] Unless command is omitted, the shell process is replaced with the specified program (which must be a real program, not a shell builtin or function). Any redirections on the exec command are marked as permanent, so that they are not undone when the exec command finishes. - Dave Rivers - > > Roman > > > -- > Roman Katsnelson > Graphnet, Inc. > romank@graphnet.com > > To Unsubscribe: send mail to majordomo@FreeBSD.org > with "unsubscribe freebsd-questions" in the body of the message > To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-questions" in the body of the message