[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Help-bash] Different methods of running scripts; subshells and exec
From: |
Michael Convey |
Subject: |
Re: [Help-bash] Different methods of running scripts; subshells and execute privileges |
Date: |
Wed, 19 Aug 2015 17:42:59 -0700 |
On Wed, Aug 19, 2015 at 7:38 AM, Greg Wooledge <address@hidden> wrote:
> The "exec" command is the shell's way of calling execve() or related
> system calls. If you're familiar with the fork/exec model of Unix
> processes, this is the exec half of that.
>
> In simple terms, exec replaces one running process with a different
> program. The new program takes over where the original one left off.
> It keeps the same process ID, the same enviroment, and the same open
> files.
>
> Where this is normally used in bash is when writing a "wrapper script".
> See http://mywiki.wooledge.org/WrapperScript for some examples.
>
Very helpful, thank you. According to the man page for execve() [
http://man7.org/linux/man-pages/man2/execve.2.html]:
============================
An interpreter script is a text file that has execute permission enabled
and whose first line is of the form:
#! interpreter [optional-arg]
The interpreter must be a valid pathname for an executable which is not
itself a script. If the filename argument of execve() specifies an
interpreter script, then interpreter will be invoked with the following
arguments:
interpreter [optional-arg] filename arg...
============================
When running a script via exec /path/script; because the first line of a
bash script has the line "#! /bin/bash", isn't execve() just replacing the
current bash shell by opening /bin/bash all over again (with the same PID)?
Isn't this essentially the same as creating a subshell? If so, this
contradicts the idea that "exec /path/script" doesn't create a subshell.
Or, is it not considered a subshell because it is a new instance of bash
that does not inherit anything from the replaced shell?
- [Help-bash] Different methods of running scripts; subshells and execute privileges, Michael Convey, 2015/08/18
- Re: [Help-bash] Different methods of running scripts; subshells and execute privileges, Ken Irving, 2015/08/19
- Re: [Help-bash] Different methods of running scripts; subshells and execute privileges, Greg Wooledge, 2015/08/19
- Re: [Help-bash] Different methods of running scripts; subshells and execute privileges, Michael Convey, 2015/08/19
- Re: [Help-bash] Different methods of running scripts; subshells and execute privileges, Greg Wooledge, 2015/08/19
- Re: [Help-bash] Different methods of running scripts; subshells and execute privileges,
Michael Convey <=
- Re: [Help-bash] Different methods of running scripts; subshells and execute privileges, Greg Wooledge, 2015/08/20
- Re: [Help-bash] Different methods of running scripts; subshells and execute privileges, Michael Convey, 2015/08/20
- Re: [Help-bash] Different methods of running scripts; subshells and execute privileges, Michael Convey, 2015/08/24
- Re: [Help-bash] Different methods of running scripts; subshells and execute privileges, Greg Wooledge, 2015/08/24
- Re: [Help-bash] Different methods of running scripts; subshells and execute privileges, Michael Convey, 2015/08/24
- Re: [Help-bash] Different methods of running scripts; subshells and execute privileges, Greg Wooledge, 2015/08/24
- Re: [Help-bash] Different methods of running scripts; subshells and execute privileges, Michael Convey, 2015/08/24
- Re: [Help-bash] Different methods of running scripts; subshells and execute privileges, Greg Wooledge, 2015/08/24