Shell Redirection with Exec command in Unix / Linux

Lets see an example to perform Shell Redirection with Exec

In Unix shells exec is a builtin command. Here is how to check if a command is a shell builtin.

The $? when evaluated by the shell results in the exit status of the previous command. A zero return value indicates that the command executed successfully. Execute the same set of commands above, but with builtin ls and see what happens.

Back to exec, it can redirect input and output of the current shell when executed without a command.

Standard output redirection:

Standard error redirection:

So, exec is useful when writing a shell script that needs to log output of commands to different files.

 

 

I hope this has been useful for you and I’d like to thank you for reading. If you like this article, please leave a helpful comment and share it with your friends.

Leave a Reply

Your email address will not be published. Required fields are marked *