[英]Run shell script by double clicking .desktop file to launch python script
[英]How to make shell script launch python script?
我需要一個.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
也許是因為shebang (或hashbang )。 關於什么是shebang (wiki) 。
#!bin/bash
^
python /Users/username/Desktop/IF.py
這意味着系統將使用bin/bash
來運行該程序,但是bin/bash
意味着path/bin/bash
。
例如,如果您在/home
則系統將使用/home/bin/bash
運行該程序。
我認為您需要這樣做:
#!/bin/bash
python /Users/username/Desktop/IF.py
請注意,我將#!bin/bash
替換為#!/bin/bash
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.