Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

How to execute a a terminal file ?

I need to execute a file with terminal commands without open the terminal.


I just want to double click the file and get the terminal open and the commands executed like when you run a CMD file in Windows.


I created a file.command but it did not work.


Thanks !

iMac, Mac OS X (10.7.2)

Posted on Feb 18, 2012 1:46 PM

Reply
11 replies

Feb 19, 2012 3:07 AM in response to SeeYa32

Thanks for your quick response.


That was the first issue I had but I solved it.


Now the Terminal open and give me this message


Last login: Sat Feb 18 10:00:53 on ttys003

Juans-iMac:~ jmg$ /Users/jmg/Documents/Backup.command ; exit;

/Users/jmg/Documents/Backup.command: line 1: {rtf1ansiansicpg1252cocoartf1138cocoasubrtf230: command not found

/Users/jmg/Documents/Backup.command: line 2: syntax error near unexpected token `}'

/Users/jmg/Documents/Backup.command: line 2: `{\fonttbl\f0\fswiss\fcharset0 Helvetica;}'

logout


[Process completed]


I got this message, no matter which .command file I try to open.


Thanks again !

Feb 19, 2012 3:49 AM in response to juan from Buenos aires

It would be nice to see that file so that we can see the context. Hope it isn't too long.


Note, if I understand what I am seeing above with your error message line 1 of you script looks like???


{rtf1ansiansicpg1252cocoartf1138cocoasubrtf230


If that is correct of course that's an error since that isn't a shell command line. Similarly line 2.


By any chance did you create that script as a .rtf file? That's what those lines look like. It should be a plain text file.


If you insist on using something like TextEdit then set it to "Make Plain Text" as opposed to "Make Rich Test" in TextEdit's Format menu.


I recommend you use a better test editor, for example BBEdit, TextWrangler, and a whole host of other text editers better suited for the purpose.

Feb 19, 2012 3:57 AM in response to juan from Buenos aires

For running scripts in the shell you don't even need a .command extension. For example, here's a line,


echo "hello world"


Save it in a file, call the file "hello", with whatever you are using as a text editor, and not a .rtf (rich text file). Then in terminal do,


chmod +x "hello"


and then type,


hello


You will see "hello world " on your terminal. I'm assuming file "hello" is in the current directory.


Just in case you missed the lines I added to the above post I repeat what I added here:


I recommend you use a better test editor, for example BBEdit, TextWrangler, and a whole host of other text editors better suited for the purpose.

How to execute a a terminal file ?

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple ID.