问题
so I have this simple executable .command file:
#!/bin/bash
cd Desktop;
python hoi.py;
exit;
Whenever I run this, it displays this in the terminal:
Tom-Diterwich:~ student$ /Users/student/Desktop/run.command ; exit;
/Users/student/Desktop/run.command: line 1:{rtf1ansiansicpg1252cocoartf1348cocoasubrtf170: command not found
/Users/student/Desktop/run.command: line 2: syntax error near unexpected token `}'
/Users/student/Desktop/run.command: line 2: `{\fonttbl\f0\fmodern\fcharset0 Courier;}'
logout
[Process completed]
Why does it do this?
回答1:
You have inadvertently saved the file as RTF (Rich Text Format) using TextEdit, whereas the bash
shell just wants plain text rather than documents containing italicised, bold or large font text.
Load the file again in TextEdit and press
⇧+⌘+T
this corresponds to clicking menu items: Format->Make Plain Text. Now re-save over the existing file and all will work.
By the way, you can remove all the semi-colons and the exit
as they are superfluous.
来源:https://stackoverflow.com/questions/41910170/how-would-i-run-this-as-an-apple-executable-file