Author Topic: The env-mystery on PCLOS KDE (Python scripting) [Solved]  (Read 753 times)

Offline jake_mcaga

  • Jr. Member
  • **
  • Posts: 14
The env-mystery on PCLOS KDE (Python scripting) [Solved]
« on: February 26, 2011, 06:29:17 AM »
Been reading Core Python Programming by Wesley Chun. On p.71-72 he mentions the first line should be a Unix start-up line:
        
     #/usr/bin/env python

I've put this on the first line in my scripts as recommended, but it doesn't work. Reading up on 'env' doesn't quite clarify either. env is used for deleting or changing variables in the environment, so what does it do standing by itself with only the python word after it? Running the command /usr/bin/env on the CLI brings up the whole family of environment variables, and typing /usr/bin/env python on the CLI only brings up the Python interpreter.

Can someone help? Or do I  need to run my scripts with [python ex_file.py] ?
« Last Edit: May 02, 2011, 06:53:12 AM by jake_mcaga »

Offline AS

  • Hero Member
  • *****
  • Posts: 4098
  • Have a nice ... night!
Re: The env-mystery on PCLOS KDE (Python scripting)
« Reply #1 on: February 26, 2011, 06:36:01 AM »
Hi,

because scripts are really text files, they are really 'interpreted' (vs. executed), and to let kernel know who is the interpret the unix convention is to put
in the first line of the script the name of the interpret. In your specific case, what reported in the book (/usr/bin/env) can be either a placehoder or a typo.

For use of python in PCLinuxOS however the line should read as:
#/usr/bin/python

EDIT: additionally you should change mode setting of your python program file to allow execution:
chmod a+x your-python-file

AS


« Last Edit: February 26, 2011, 06:38:40 AM by as »

Offline jake_mcaga

  • Jr. Member
  • **
  • Posts: 14
Re: The env-mystery on PCLOS KDE (Python scripting)
« Reply #2 on: February 28, 2011, 03:10:31 AM »
Hi AS :)

I've answered my own question:
The start-up line: #/usr/bin/env python on page 72 is a 'typo'. It should read #!/usr/bin/env instead. The exclamation character is omitted.

Thanks for answering :)