I am a unix newbie and exploring the functionalities of shebang line.
For example, let's say I have a program program.py to execute.
One way to execute is to directly call the interpreter command:
python program.py
If using the shebang line, I will include:
#!/usr/bin/env python
at the beginning of file to tell the system what interpreter to use.
Then why do we in this case need to make the file 'executable' by calling:
chmod +x program.py
and then call:
./program.py
to execute it,
instead of directly calling:
program.py
to execute it?
You're asking two unrelated questions.
We make it executable so that the OS reads the shebang line.
We prefix it with "./" so that the shell can find it and tell the OS to execute it, since the script is unlikely to be in a directory listed in
$PATH
.