The terminal underpinnings in OS X are the same as those used in Linux. What you are specifically looking for is commonly referred to as "Shell Scripting".
The default shell when you open
Terminal.app (located in
/Applications/Utilties) is the bash shell.
OS X has had a built-in shell handler accessible via Finder and other applications via the
.command extension, though frustratingly not via the
.sh extension. However, setting the script up to run via the Finder is even more complicated still.
- Create a simple shell script, like your example I've made a Hello World application:
echo "Hello World"
Save this file as
Give this file permission to be executed.
chmod u+x HelloWorld.command should do that.
Open the directory where you saved this file in Finder. Then double click on the
This will open up a terminal and execute the script, the output on my computer is the following:
$ /Users/jason/Applications/HelloWorld.command ; exit;
The alternative way of executing this file is while still in the Terminal yourself, simply issue
./HelloWorld.command assuming you're in the same directory as the file.
Doing so will result in much simpler output:
jason-mac Applications $ ./HelloWorld.command
jason-mac Applications $
You've just created and executed a shell script in OS X!