What's the difference of using #!/usr/bin/env or #!/bin/env in shebang?

前端 未结 4 836
野的像风
野的像风 2021-02-19 07:19

Will there be any difference or it\'s just a personal choice?

4条回答
  •  有刺的猬
    2021-02-19 08:00

    Mikel explanation is great, it misses just a small fact (which is rather important), it's only one argument being passed including all spaces:

    #! 
    

    Results in calling:

    $  '' path_to_calling_script
    

    So for Example:

    $ cat /tmp/test
    #!/usr/bin/env python
    print "hi"
    
    $ /tmp/test
    

    is the same as calling:

    $ /usr/bin/env "python" /tmp/test
    

    The quotes try to show that if you add any flag or other values will be part of the argument being called.

     #!/bin/bash -c /bin/env python
    

    Will be interpreted as:

     $ /bin/bash "-c /bin/env python"
    

    Which won't work.

提交回复
热议问题