[OT] Is it "#!/bin/bash", "#! /bin/bash", or does it even matter?
Thomas Olsen
tanghus at gmail.com
Sun Oct 25 02:36:04 UTC 2009
On 25/10-2009 03:09 "Joe(theWordy)Philbrook" <jtwdyp at ttlc.net> wrote:
> Memory can be a silly thing.
> I know that if I want a script to be run by a particular shell (such as
> bash) then I want the first line of the script to start with "#!" followed
> by the path to the shell involved. But it suddenly occurred to me that I
> may have been doing it wrong.
>
> I'm not sure if it's supposed to look like:
> #!/bin/bash
> or like:
> #! /bin/bash
> And for that matter how about:
> #! /bin/bash
> Which I'm likely to get because to be honest I can never remember if it's
> /bin/bash or /usr/bin/bash etc... So since I tend to use vim to edit my
> scripts, what I actually tend to do is "ggO#!^[:r!which bash^MkJ" But now I
> wonder if I need to add "x" or "2x" to the above...
>
> I figure that if one of the above wasn't interpreted as a request to run
> the script in bash then it would be treated as a comment line. And the
> only way I'd know that was happening would be if I actually included
> something that worked in bash, but not in whichever shell happened to run
> the script.
>
> And I'm not good enough with any of the other shells to be sure I'd spot
> the problem. So I'm not really sure if my scripts are correctly specifying
> that they should be run in the bash shell. Would some better script
> programmer than I am, kindly set me straight.
>
> Thanks
>
I'm absolutely not a good shell scripter but this works for me:
#! /usr/bin/env bash
Then the "env" (environment I guess?) utility checks where bash is located.
But I think that all your suggestions would work on 99.9% GNU/Linux systems.
--
Best Regards / Med venlig hilsen
Thomas Olsen
More information about the kubuntu-users
mailing list