What is the Shell !

Ric

Joined
May 14, 2004
Messages
4,260
Reaction score
5
Well, a Shell is a program that allows you the user an easy and convenient way of executing (running) programs in UNIX.

On the Mac you have an Application called "Terminal" this is what we access the Shell with...

The Shell responds to any 'commands' passed to it...it then passes these on to the UNIX kernel to execute them.

One of the best features of the shell, is that it allows you to create scripts. In essence scripts are lists of commands that you want to run !

So, you can create a shell script that does a repetitive task for you, then save it as a executable file and you can then 'run' the script using a single word or by allowing cron to run it at a specific time...

...this all might sound !@$£%@ but I'll put a few examples up and it will become clearer.
 

Ric

Joined
May 14, 2004
Messages
4,260
Reaction score
5
Re: What is a Shell !

First, as always before working with the Terminal, make sure that you are backed up !

We are not going to do anything that will do any damage, but if you accidently type in the wrong commands, or decide to experiment, then it is very easy to mess up...

...so back up first !
 

Ric

Joined
May 14, 2004
Messages
4,260
Reaction score
5
Re: What is a Shell !

Fire up terminal...

Applications-->Utilities-->Terminal

and you should get greeted with a screen like below, yours however will be black text on a white background ! I've changed mine for a more 'Retro' feel ! (How to later.)



terminal001.jpg
 

Ric

Joined
May 14, 2004
Messages
4,260
Reaction score
5
Re: What is a Shell !

So what does it mean...

Last login: Fri Nov 11 12:03:23 on console

This is the last time that 'you' or someone using your Mac opened a terminal window. Either locally or remotely

Welcome to Darwin!

Darwin is the underlying version of UNIX that your Mac is running... to quote Apple...

"Beneath the appealing, easy-to-use interface of Mac OS X is a rock-solid foundation that is engineered for stability, reliability, and performance. This foundation is a core operating system commonly known as Darwin. Darwin integrates a number of technologies, most importantly Mach 3.0, operating-system services based on 4.4BSD (Berkeley Software Distribution), high-performance networking facilities, and support for multiple integrated file systems."

The last line...

computers-powerbook-g4-17:~ computer$

Is your prompt if you can see the prompt then that means you can enter a 'command'...

computers-powerbook-g4-17: is your computers name this is mine, yours will be different...

:~ computer$ tells us where we are and who we are !

The character after the colon : is called a Tilde ~ this signifies your "Home" directory (folder), this is important...this means that you are currently in 'that' folder !

This changes to let you know where you are !

The next bit computer$ is the username that I am currently logged in as...in this instance I am called 'computer'

Again as before, if I log in as a different 'user' the prompt would change !
 

Ric

Joined
May 14, 2004
Messages
4,260
Reaction score
5
Re: What is a Shell !

When working this way, in the Terminal Folders are known as Directories...so that's what we will use to.

Below you can see the prompt has changed because I have moved directories...


Terminal002.jpg



The prompt is now displaying...

computers-powerbook-g4-17:/applications computer$

The important bit is /applications this tells us that we are in the Applications directory (folder !)
 

Ric

Joined
May 14, 2004
Messages
4,260
Reaction score
5
Re: What is a Shell !

Navigation...

...how do I move around.

Well here's a few commands that may help...

cd change directory (now do you see why we aren't using the term folder!)

example

cd /

cd /usr

cd /usr/

so what's happenning !

Well cd / means change the current directory to the root level...in normal GUI terms go to the lowest level possible, ie the Hard Disk.

So My Hard Disk is called 'Big Mac' if I double click on it in the Finder I see this...

bigmac.jpg


Yours will look similar...

Now if we go back to Terminal and type

cd /

then press the returnkey (do this after every command !)

then type

ls

then press the returnkey (do this after every command !)

ls is "LS" in lowercase, this is the UNIX command/program for 'list'...


Terminal003.jpg



As you can see there's a lot more there than you can see...with the Finder !
 
Joined
Nov 17, 2011
Messages
3
Reaction score
0
Some of the more interesting features are the commands that you do not have under other unix systems.

The most powerful OSX unix command is the open command, it's like double clicking in finder.

eg
cd ~/Documents
open History.txt

Will open History.txt in Text Edit or whatever you've defined as your default program to open .txt files in.

open can also open finder windows.

eg
open .

will open the current shell directory in a finder window.

Also it can open applications, without the need to specify the full path.

slow way

open /Applications/TextEdit.app

faster way

open -a textedit

If you're interested in more OSX only terminal commands check out my article;
http://silicontrip.net/~mark/macosxcommandline/

Mark
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top