[Novalug] Novalug Digest, Vol 65, Issue 88
lug-user at drmikehenry.com
Sat Mar 17 08:17:46 EDT 2012
On 03/16/2012 08:23 PM, Jamie Duncan wrote:
> Might be bending the rules a little, but a few lines of Python does
> the same thing, and is infinitely easier to read:
> [root at desktop01 ~]# cat ispath
> #!/usr/bin/env python
> import sys
> if sys.argv in sys.path:
> print "True"
> print "False"
One easily fixed problem is that the original quiz required the
script to return success or failure, rather than to print "True"
But a larger concern is that Python's ``sys.path`` variable does
not mean the same thing as the ``PATH`` environment variable.
$ echo $PATH
Here are just the first couple of entries in my ``sys.path``::
$ python -c 'import sys; print(sys.path[:3])'
``sys.path`` is for Python's own libraries. It doesn't include
the directories in the ``PATH`` environment variable, e.g.::
$ python -c 'import sys; print(sys.path)' | grep /bin
Here's one quick attempt in Python that uses ``PATH``::
$ cat inpath
if sys.argv in os.environ['PATH'].split(':'):
$ if ./inpath /bin; then echo yes; else echo no; fi
$ if ./inpath bin; then echo yes; else echo no; fi
: Jon LaBadie's correctness concerns are ignored here to
match the spirit of the original Python code (i.e., because I'm
More information about the Novalug