I came across this line #!/usr/bin/env and was wondering what is this and for what? I browsed some articles to get some overview about it. Any script beginning with #! is called shebang(other names are hashbang, sha-bang etc). When a script with shebang is run, it passes the file as an argument to the specified program instead of trying to execute it.
The form of a shebang interpreter directive is as follows:
- #! interpreter [optional-arg]
The interpreter must be an absolute path to an executable
In order to run the script, we need to tell the shell three things:
That the file is a script –>accomplished using shebang #!
Which interpreter we want to execute the script
The path of said interpreter
2 and 3 is accomplished using env.
Some typical shebang lines:
#!/bin/sh— Execute the file using sh
#!/usr/bin/perl— Execute using Perl
#!/usr/bin/python— Execute using Python
Shebang lines may include specific options that are passed to the interpreter.