我有这样一个程序来检查命令行中的数据方法:
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('_')]
print(methods)
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']
我想直接从 bash 运行该程序,例如:
$ check_methods.py list
-bash: check_methods.py: command not found
如何实现呢?
答案1
指定脚本的路径,因为它不在$PATH
.
./check_methods.py list
并且永远不要添加.
到$PATH
.