Automation, Orchestration, and Scripting

A script begins with #!/usr/bin/env python3. The user's PATH lists /opt/py312/bin before /usr/bin, and both contain python3. Which interpreter runs the script when the user executes it?

Show the answer

Correct answerC. /opt/py312/bin/python3, the first match in the user's PATH

AWhy not this: env searches every directory in PATH in order, not only system directories.

BWhy not this: PYTHONPATH sets where Python looks for modules; it does not choose the interpreter.

CWhy this is right: Env runs the first python3 found in PATH, which here is in /opt/py312/bin.

DWhy not this: env has no interpreter of its own; it finds and runs the named program.

The env utility searches the directories in PATH for python3 and runs the first match, so the interpreter's location does not need to be hard-coded. A fixed path such as /usr/bin/python3 would ignore PATH.