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: Greg Wooledge
Subject: Re: [Help-bash] Different methods of running scripts; subshells and execute privileges
Date: Wed, 19 Aug 2015 08:51:19 -0400
User-agent: Mutt/1.4.2.3i

On Tue, Aug 18, 2015 at 06:30:21PM -0700, Michael Convey wrote:
>    - These methods are equivalent do not require file execute privileges
>    and are run in subshells:
>       - bash /path/script.sh
>       - sh /path/script

No, these are not equivalent.  One of them launches the first instance
of "bash" in your PATH and hands your script to it, to be interpreted.
The other launches the first instance of "sh" in your PATH and hands
your script to it, to be interpreted.

sh is not bash.  Even if ON YOUR SINGLE COMPUTER /bin/sh happens to be
a symlink to bash, bash behaves differently when invoked with the name
"sh".

On most other computers in the world, sh isn't even a symlink to bash
in the first place.  You will get widely varying results if you attempt
to interpret a script that uses bash extensions in "sh" on various
operating systems.  (On platforms where sh is really ksh in disguise,
many of the older bash extensions may actually work, because bash and
ksh share many extensions.  But there are still incompatibilities.)

What exactly are you trying to do?  If you want to install a bash script
as a usable program on a target system, just put it in /usr/local/bin
(or some other directory in PATH), give it +x permissions, and DON'T
give it a .sh or .bash extension.  Just name it whatever you want users
to type when they use it ("foo" not "foo.sh").



reply via email to

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