atelszewski at gmail.com
Wed Sep 2 15:09:45 UTC 2015
On 02/09/15 16:51, John Vogel wrote:
> On Wed, 2 Sep 2015 15:52:30 +0200
> Andrzej Telszewski <atelszewski at gmail.com> wrote:
>> 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
>> It seems that shebang has only meaning if the script is invoked
>> directly, that is:
>> $ ./whatever.SlackBuild
>> $ 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):
Yes, I'm sure;)
> -- start ./test_script
> 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
That's it. If you use -c switch, then the script is executed as if you
used ./, that is, the shebang is processed. Try running your test
without the -c switch and placing some constructs that are only
understood by one of the shells.
$ sh -c ./whatever.SalckBuild
is equivalent to:
$ sh ./whatever.SalckBuild
will process the script by whichever shell is linked to the sh, without
taking into account the shebang (maybe there are shells, that upon
seeing shebang in the first line don't treat it as comment, but I don't
know about it).
> 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.
> SlackBuilds-users mailing list
> SlackBuilds-users at slackbuilds.org
> Archives - http://lists.slackbuilds.org/pipermail/slackbuilds-users/
> FAQ - http://slackbuilds.org/faq/
More information about the SlackBuilds-users