[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
printf '$0=%s\n' "$0"
-- 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

The output for each is identical:

But if I change the shebang line to '#!/bin/dash', then the
output for all is:

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.


More information about the SlackBuilds-users mailing list