help-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Help-bash] Different methods of running scripts; subshells and exec


From: Ken Irving
Subject: Re: [Help-bash] Different methods of running scripts; subshells and execute privileges
Date: Tue, 18 Aug 2015 23:27:32 -0800
User-agent: Mutt/1.5.20 (2009-06-14)

On Tue, Aug 18, 2015 at 06:30:21PM -0700, Michael Convey wrote:
> Here are the methods I know of:
> 
>    - These methods are equivalent do not require file execute privileges
>    and are run in subshells:
>       - bash /path/script.sh
>       - sh /path/script
>    - This method requires file execute privileges and is run in a subshell:
>       - /path/script.sh
>    - These methods are equivalent and do not require file execute
>    privileges and are not run in subshells:
>       - source /path/script.sh
>       - .  /path/script.sh
>    - The following 'exec' methods do require file execute privileges, do
>    not run in a subshell, but can only be run with methods that do run in
>    subshells:
>       - exec bash /path/script.sh
>       - exec sh /path/script.sh
>       - exec /path/script.sh
> 
> Please confirm the above is correct. Also, the exec method is confusing.
> According to my LPIC book:
> 
> "exec is not truly a script execution method. It does not create a subshell
> but instead replaces the current shell with an executable image environment
> to run the script. Only execution methods that create a subshell will work
> with the exec command. The exec program???s primary value is not in running
> scripts. Instead, it is often used to run a program from within a script."
> 
> I'm unclear on this explanation. I would be grateful if one of you experts
> could provide a better explanation. Thanks in advance.

Exec is pretty fundamental to how a unix system works, certainly worth
knowing about.  It's usable through the exec executable or shell built-in,
and is used by programs running in other languages.

A shell script might set some variables, open some files, define
some functions, etc, then exec a program to run in that environment.
The operating system running behind exec will only run the program if
it's actually executable and if permissions permit it.

Not sure what the question is, but it sounds more like a general operating
system one than anything or much to do with bash.

Ken



reply via email to

[Prev in Thread] Current Thread [Next in Thread]