[TUHS] Shell builtin exec

Chet Ramey chet.ramey at case.edu
Wed Aug 21 10:38:08 AEST 2019

On 8/20/19 5:10 PM, Adam Thornton wrote:
> This is probably the place to ask:
> I understand why the shell builtin "exec" is the same as the syscall exec()
> in the sense of "replace this process with that one."  But why is it also
> the way to redirect filehandles in the current shell?  (That is, why isn't
> the redirection named something else?)

It was probably a side effect that turned out to be useful. The `exec'
builtin performs redirections without a way to undo them, because why
bother, and executes its arguments as a command with arguments, as if it
were in a child process.

The original Bourne shell just performed the redirections and returned
if there weren't any arguments, leaving the non-undoable redirections
in place.

``The lyf so short, the craft so long to lerne.'' - Chaucer
		 ``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, UTech, CWRU    chet at case.edu    http://tiswww.cwru.edu/~chet/

More information about the TUHS mailing list