When to Use Exec?
Exec Is Useful When You Want to Run a Command, but You Don't Want a Bash Shell to Be the Parent Process. When You Exec a Command, It Replaces Bash Entirely...
exec is useful when you want to run a command, but you don't want a bash shell to be the parent process. When you exec a command, it replaces bash entirely — no new process is forked, no new PID is created, and all memory controlled by bash is destroyed and overwritten.
What is purpose of exec command?
The exec command is a powerful tool for manipulating file-descriptors (FD), creating output and error logging within scripts with a minimal change. In Linux, by default, file descriptor 0 is stdin (the standard input), 1 is stdout (the standard output), and 2 is stderr (the standard error).
Why we use exec command in Linux?
exec command in Linux is used to execute a command from the bash itself. This command does not create a new process it just replaces the bash with the command to be executed. If the exec command is successful, it does not return to the calling process.