Sample Header Ad - 728x90

Why is it better to use "#!/usr/bin/env NAME" instead of "#!/path/to/NAME" as my shebang?

680 votes
11 answers
304993 views
I notice that some scripts which I have acquired from others have the shebang #!/path/to/NAME while others (using the same tool, NAME) have the shebang #!/usr/bin/env NAME. Both seem to work properly. In tutorials (on Python, for example), there seems to be a suggestion that the latter shebang is better. But, I don't quite understand why this is so. I realize that, in order to use the latter shebang, NAME must be in the PATH whereas the first shebang does not have this restriction. Also, it appears (to me) that the first would be the better shebang, since it specifies precisely where NAME is located. So, in this case, if there are multiple versions of NAME (e.g., /usr/bin/NAME, /usr/local/bin/NAME), the first case specifies which to use. My question is why is the first shebang preferred to the second one?
Asked by TheGeeko61 (7181 rep)
Jan 21, 2012, 01:06 AM
Last activity: Jul 2, 2024, 06:24 AM