如何让shell脚本启动python脚本?
我需要一个如何让shell脚本启动python脚本?,python,shell,Python,Shell,我需要一个.command文件,该文件可以在与其相同的目录中启动python脚本 到目前为止,我已经了解到: #!bin/bash python /Users/username/Desktop/IF.py 但每次终端返回相同的错误 Last login: Sun Oct 11 01:48:38 on ttys000 MacBook-Pro:~ username$ /var/folders/m7/yf7p3vdj2mx0l9r7qb68rttc0000gn/T/Cleanup\ At\ Star
.command
文件,该文件可以在与其相同的目录中启动python脚本
到目前为止,我已经了解到:
#!bin/bash
python /Users/username/Desktop/IF.py
但每次终端返回相同的错误
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]
请注意,错误在我的两行代码中的第3行…为什么不从一开始就启动python脚本呢?您可以在顶部添加一个shebang,如下所示:
#! /user/bin/env python
... the rest of your python script here
然后只需授予脚本可执行权限:
chmod +x nameofscript.py
然后像这样启动它:
./nameofscript.py
如果您不希望脚本依赖于环境,只需使用以下shebang:
#! /usr/bin/python
为什么不从一开始就启动python脚本呢?您可以在顶部添加一个shebang,如下所示:
#! /user/bin/env python
... the rest of your python script here
然后只需授予脚本可执行权限:
chmod +x nameofscript.py
然后像这样启动它:
./nameofscript.py
如果您不希望脚本依赖于环境,只需使用以下shebang:
#! /usr/bin/python
也许是因为“shebang”(或“hashbang”)。大约
这意味着系统将使用
bin/bash
运行此程序,但bin/bash
意味着path/bin/bash
例如,如果您在/home
中,则系统将使用/home/bin/bash
运行此程序
我想你需要这个:
#!/bin/bash
python /Users/username/Desktop/IF.py
注意,我替换了#!bin/bash
至#/bin/bash
可能是因为shebang(或hashbang)。大约
这意味着系统将使用
bin/bash
运行此程序,但bin/bash
意味着path/bin/bash
例如,如果您在/home
中,则系统将使用/home/bin/bash
运行此程序
我想你需要这个:
#!/bin/bash
python /Users/username/Desktop/IF.py
注意,我替换了
#!bin/bash
至#/bin/bash
shebang行需要#/bin/bash
不是#!bin/bash
shebang行需要是#/bin/bash
不是#!bin/bash
这是一个好主意,但如果脚本依赖于环境,则不会加载它;这可能有一些副作用。这是一个好主意,但如果脚本依赖于环境,它将不会被加载;这可能有一些副作用。