Since the beginning of times (Unix, i.e. January 1, 1970), it was recommended to use shebang / hashbang in the beginning of the script - a line indicating the interpreter used, for example
#!/bin/bash echo 'hello world' #!/usr/bin/python print 'hello world' #!/usr/bin/python3 print('hello world')
Recently I came across a recommendation to use this form instead:
#!/usr/bin/env bash echo 'hello world' #!/usr/bin/env python print 'hello world' #!/usr/bin/env python3 print('hello world')
Please explain how it works and what are the advantages of this approach? If there are limitations and / or disadvantages compared to the usual way, then I would like to hear about them.
/bin/bash
, and in FreeBSD it is in/usr/local/bin/bash
and the first option does not start. At one time I ran into it and now I use only the second option everywhere) - andreymal/usr/bin/env
will someday move someone too ... - andreymal