help-bash
[Top][All Lists]
Advanced

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

[Help-bash] Different methods of running scripts; subshells and execute


From: Michael Convey
Subject: [Help-bash] Different methods of running scripts; subshells and execute privileges
Date: Tue, 18 Aug 2015 18:30:21 -0700

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.


reply via email to

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