Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 21 Aug 1998 16:29:23 -0400 (EDT)
From:      Thomas David Rivers <rivers@dignus.com>
To:        freebsd-questions@FreeBSD.ORG, romank@graphnet.com
Subject:   Re: "clear" curiosity
Message-ID:  <199808212029.QAA02219@lakes.dignus.com>
In-Reply-To: <35DDC102.CE22AD57@graphnet.com>

next in thread | previous in thread | raw e-mail | index | archive | help
> 
> 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



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199808212029.QAA02219>