2

Does running exec in an interactive shell do anything? I mean simply exec, with no parameters whatsoever.

What about in a script?

If it does do something, what does it do?

1
  • You might be interested in reading answers to a related question What's the difference between eval and exec? They already cover essentially what the two existing answers already did , and then cover extra information Commented May 4, 2019 at 22:41

2 Answers 2

3

If command is not specified, any redirections can take effect in the current shell. This is short version of what man page says .That I understand as when exec is executed empty it does not start a new shell , does not make changes in the current, and returns code 0 which means it was executed without errors.

3

Yes:

When called with a command as argument.

Normally when you run a command, it calls fork and exec (plus pipe, etc). But when you add exec at the start (e.g. exec ls), it does not call fork, therefore the shell is replaced by the command. That is the command runs in the same process as the shell was in (the shell no longer exists).

When called without a command.

It applies redirections, that are then in affect afterward.

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.