When I try to execute the exec ls
, my putty session is getting closed. What is the difference between ls
and exec ls
?
Why do we need the exec
command, and what are the uses of this command ?
When I try to execute the exec ls
, my putty session is getting closed. What is the difference between ls
and exec ls
?
Why do we need the exec
command, and what are the uses of this command ?
exec
replaces the current process (the shell) with the new process. If you call a program without exec
, the shell will fork a new process and then replace the new process with the program.
exec
is a shell built-in command.
In the manpage it says
If exec is specified with command, it shall replace the shell with command without creating a new process.
So when you execute exec ls
in the shell, your shell will be replaced with the ls
process; when this process ends, the shell exits. Compared with source
or .
, this could be useful in shell scripts.