从命令行调用 python 脚本而不输入“python"第一的 [英] Calling a python script from command line without typing "python" first
问题描述
问题:在命令行中,如何调用 python 脚本而不必在脚本名称前键入 python
?这甚至可能吗?
Question: In command line, how do I call a python script without having to type python
in front of the script's name? Is this even possible?
信息:
我写了一个方便的脚本来从命令行访问 sqlite 数据库,但我有点不喜欢必须输入python SQLsap args",而宁愿只输入SQLsap args".我不知道这是否可行,但最好知道是否可行.不仅仅是这个程序.
I wrote a handy script for accessing sqlite databases from command line, but I kind of don't like having to type "python SQLsap args" and would rather just type "SQLsap args". I don't know if this is even possible, but it would be good to know if it is. For more than just this program.
推荐答案
您可以在脚本的第一行添加一个shebang:
You can prepend a shebang on the first line of the script:
#!/usr/bin/env python
这将告诉您当前的 shell 将脚本输入到哪个命令中.
This will tell your current shell which command to feed the script into.
这篇关于从命令行调用 python 脚本而不输入“python"第一的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!