Re: Stupid shebang tricks
Ben Finney <email@example.com> writes:
> On 11-May-2005, Goswin von Brederlow wrote:
>> Ben Finney <firstname.lastname@example.org> writes:
>> > The good thing about the (standard?) shebang convention -- using a
>> > first line of '#!/path/to/shell' in the executable file -- is that
>> > you can have executable scripts shared even between different
>> > Unices and architectures. If the named shell exists, it should be
>> > able to execute the script. (If not, that's a bug in the shell or
>> > the script.)
>> Something you sometimes see is
>> #!/usr/bin/env python
>> Env then looks for python in the path and executes the script. Since
>> env is small and a system thing it is available everywhere while
>> python can be anywhere. That way you can have your python in
>> /usr/bin/arch-os/ for each arch/os combo and the script still works.
> Yes, I've always been impressed with that trick (in direct proportion
> to the hatred I had of '#!/usr/bin/perl' and '#!/usr/local/bin/perl'
Perl is certainly another candidate for it if you have to work with
multiple OS and archs.
> To what extent should that be used? Is it reasonable to do it for
> *any* shebang line? '#!/usr/bin/env make'? '#!/usr/bin/env bash'?
> Are there any downsides?
I wouldn't use it for bash as I wouldn't be using bash but /bin/sh.
But then there are some OSes where /bin/sh is to screwed up and you
want bash instead none the less.
At university I use #!/bin/sh in combination with testing if the shell
actualy is bash and reexecuting oneself with bash if not. That seem to