I have such a program to check methods of data from the command line:

me at me in ~/Desktop/Coding/codes
$ cat check_methods.py
#! /usr/bin/env python
from sys import argv
methods = dir(eval(argv[1]))
methods = [i for i in methods if not i.startswith('_')]

me at me in ~/Desktop/Coding/codes
$ python check_methods.py list
['append', 'clear', 'copy', 'count', 'extend', 'index',
    'insert', 'pop', 'remove', 'reverse', 'sort']

me at me in ~/Desktop/Coding/codes
$ python check_methods.py dict
['clear', 'copy', 'fromkeys', 'get', 'items', 'keys',
    'pop', 'popitem', 'setdefault', 'update', 'values']

I'd like to run the program directly from bash, like:

$ check_methods.py list
-bash: check_methods.py: command not found

How to achieve it ?


Specify the path to the script, since it isn't in $PATH.

./check_methods.py list

And never add . to $PATH.

  • 1
    They could add $HOME/Desktop/Coding/codes to the end of $PATH if they wanted. Or move the script to $HOME/local/bin or some such location and add that to the end of $PATH. – Kusalananda May 10 '18 at 7:04
  • $ ./check_methods.py dict -bash: ./check_methods.py: Permission denied $ sudo ./check_methods.py dict sudo: ./check_methods.py: command not found Must it transmit to $PATH before it works? – JawSaw May 10 '18 at 7:08
  • 2
    No, but you need to make it executable, just like every other executable in existence. – Ignacio Vazquez-Abrams May 10 '18 at 7:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.