$ps bash ps
If I rum a simple shell script, the bash above, doesn't execute it. It invokes another bash process only for the execution of this script.
Why?
Regards, Nikhil.
On 21 Oct 2002, Nikhil Karkera wrote:
If I rum a simple shell script, the bash above, doesn't execute it. It invokes another bash process only for the execution of this script.
You need to first understand how a process is executed in unix. There is no way to create a new process. The only thing that can be done is to fork, and then exec the new process.
Whenever you enter a shell command, if it is not internal to the shell, the shell will fork and exec the new command. The same thing happens when you run a shell script.
shell scripts are interpreted, therefore they need an interpreter to be run - bash in this case.
When you run a script (any script), the shell reads the first few bytes of that script and then execs the interpreter specified after the #!.
To tell the shell not to fork and exec, you can do use .
. shell_script
This tells the shell to execute the script within the current shell, and not to spawn a new subshell.
Philip