[英]How to make shell script launch python script?
I need a .command
file that can launch a python script in the same directory as it. 我需要一个.command
文件,该文件可以在与其所在的目录中启动python脚本。
I have so far gotten this: 到目前为止,我得到了:
#!bin/bash
python /Users/username/Desktop/IF.py
But every time the Terminal returns the same error. 但是终端每次返回相同的错误。
Last login: Sun Oct 11 01:48:38 on ttys000
MacBook-Pro:~ username$ /var/folders/m7/yf7p3vdj2mx0l9r7qb68rttc0000gn/T/Cleanup\ At\ Startup/run 466235498.368.command.command ; exit;
/var/folders/m7/yf7p3vdj2mx0l9r7qb68rttc0000gn/T/Cleanup At Startup/run-466235498.368.command.command: line 3: bin/bash: No such file or directory
logout
Saving session...
...copying shared history...
...saving history...truncating history files...
...completed.
[Process completed]
Please note the error is on line 3 of the 2 lines of code I have... 请注意错误是我有两行代码的第3行...
Why not just launch the python script itself from the get-go? 为什么不从一开始就启动python脚本本身呢? You can add a shebang at the top like so: 您可以在顶部添加shebang,如下所示:
#! /user/bin/env python
... the rest of your python script here
Then just give the script executable permissions: 然后只需赋予脚本可执行权限:
chmod +x nameofscript.py
Then just launch it like so: 然后像这样启动它:
./nameofscript.py
In case you don't want the script to rely on the environment, just use the following shebang instead: 如果您不希望脚本依赖于环境,则只需使用以下shebang即可:
#! /usr/bin/python
Maybe because the shebang (or hashbang ). 也许是因为shebang (或hashbang )。 About what is shebang (wiki) . 关于什么是shebang (wiki) 。
#!bin/bash
^
python /Users/username/Desktop/IF.py
This means the system will use bin/bash
to run this program, but bin/bash
means path/bin/bash
. 这意味着系统将使用bin/bash
来运行该程序,但是bin/bash
意味着path/bin/bash
。
For example, if you're in /home
then the system will use /home/bin/bash
to run this program. 例如,如果您在/home
则系统将使用/home/bin/bash
运行该程序。
I think you need this: 我认为您需要这样做:
#!/bin/bash
python /Users/username/Desktop/IF.py
Note that I replaced #!bin/bash
to #!/bin/bash
. 请注意,我将#!bin/bash
替换为#!/bin/bash
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.