[Slackbuilds-users] bashisms?

John Vogel jvogel4 at stny.rr.com
Wed Sep 2 14:51:24 UTC 2015


On Wed, 2 Sep 2015 15:52:30 +0200
Andrzej Telszewski <atelszewski at gmail.com> wrote:

> Hi,
> 
> Today I was writing code to execute script from C code and I'd like to 
> share with you what I've found. It stroke me, but should otherwise be 
> obvious.
> 
> It seems that shebang has only meaning if the script is invoked 
> directly, that is:
> $ ./whatever.SlackBuild
> or
> $ sh -c ./whatever.SlackBuild
> 
> otherwise, shebang is nothing more than a comment...
> 
> If you run your script through sh (which links to bash), it doesn't 
> matter what the shebang is, it can be #!/bin/csh, and the script is 
> still going to be interpreted by sh.
> 
> This might be important, as sbopkg uses sh to execute the build.
> 
> -- 
> Best regards,
> Andrzej Telszewski

Are you sure? I tried to test this using the following script
(executable bit is set):

-- start ./test_script
#!/bin/bash
printf '$0=%s\n' "$0"
printf 'BASH_VERSION=%s' "$BASH_VERSION"
-- end ./test_script

When run by all the shells I have (ash,bash,dash,ksh,mksh,tcsh),
they all output the same. I used the following loop to run
the commands:

for s in ash bash dash ksh mksh tcsh sh csh ; do
/bin/$s -c ./test_script
done

The output for each is identical:
$0=./test_script
BASH_VERSION=4.3.39(1)-release

But if I change the shebang line to '#!/bin/dash', then the
output for all is:
$0=./test_script
BASH_VERSION=

At the time of running this /bin/sh -> /bin/bash. Changing
/bin/sh to point anything else (other than tcsh/csh, I never
set /bin/sh to a c shell) did not change the results.

I'm sure I could carry this testing further, but I think
the point might be proved well enough. I didn't want to
step into this discussion, as I have rather conservative
opinion about proper use of shebang and would rather not
go down this road here. But let's keep things accurate,
as far as how things actually work.

John


More information about the SlackBuilds-users mailing list