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?
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.
You can readily check whether a file is Rich Text Format (RTF) or plain text using the file
command like this:
file SOMEFILE
and you will either get:
SOMEFILE: Rich Text Format data, version 1, ANSI, code page 1252
or
SOMEFILE: ASCII text, with no line terminators
By the way, you can remove all the semi-colons and the exit
from your code as they are superfluous.
Note that you can make TextEdit
always use plain text for new documents and always save plain text by running these commands in Terminal:
# Use plain text mode for new TextEdit documents
defaults write com.apple.TextEdit RichText -int 0
# Open and save files as UTF-8 in TextEdit
defaults write com.apple.TextEdit PlainTextEncoding -int 4
defaults write com.apple.TextEdit PlainTextEncodingForWrite -int 4