bashenv

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


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


Solution

  • #!<interpreter> <arguments> tries to run <interpreter> <arguments> to read and run the rest of the file.

    So #!/usr/bin/env means that there must be a program called /usr/bin/env;
    #!/bin/env means that there must be a program called /bin/env.

    Some systems have one and not the other.

    In my experience, most have /usr/bin/env, so #!/usr/bin/env is more common.

    Unix systems will try to run <interpreter> using execve, which is why it must be a full path, and #!env without a path will not work.