Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

Spanky Deluxe

macrumors demi-god
Original poster
Mar 17, 2005
5,282
1,745
London, UK
I know this is a particular basic question, but how do I create terminal scripts that I can just type in to a terminal window and they'll just execute a few commands? Basically the equivalent to a DOS batch file.

I know its ridiculously easy but I don't know how to do it!
 

MacsRgr8

macrumors G3
Sep 8, 2002
8,284
1,753
The Netherlands
In the Terminal, create a new file: (ignore ">")
> touch test <ENTER>

Edit that file:
> pico test <ENTER>

Start off by showing it is a shell script:
> #!/bin/sh
> "type_your_command_here" (i.e. > say hello)

Save and exit:
CTRL-O <ENTER>, CTRL-X <ENTER>

Now, make it executable:
> chmod 755 test <ENTER>

Test it:
> ./test <ENTER> (if you typed "say hello", your Mac would really say "Hello" to you.

In the Finder you can put ".command" at the end of "test".
If you do that, your script will open the Terminal and run it.

Have fun! :)
 

Cromulent

macrumors 604
Oct 2, 2006
6,802
1,096
The Land of Hope and Glory
I know this is a particular basic question, but how do I create terminal scripts that I can just type in to a terminal window and they'll just execute a few commands? Basically the equivalent to a DOS batch file.

I know its ridiculously easy but I don't know how to do it!

Read up on Bash scripting, another alternative if you want a more Apple style scripting language is to use Applescript.
 

Spanky Deluxe

macrumors demi-god
Original poster
Mar 17, 2005
5,282
1,745
London, UK
Stupid question: How can I create terminal scripts?

This is probably a really basic thing for anyone that uses them but how do you create terminal scripts? Basically the equivalent to the old fashioned MS DOS batch file. :confused:
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.