Unix Introduction — Shell

김영석
3 min readFeb 28, 2018

As I am walking through OS X, I am going deep down to have thorough understanding of Unix Operating System, particularly OS X is a child of Unix series I can’t possibly ignore this part.

So, what is UNIX?

UNIX is an OS that was first developed in the 1960s, and has been developed constantly ever since then. It is a collections of programs to make the computer work properly with stable, multi-user, multi-tasking system for servers, desktops, and laptops.

Types of UNIX

The most common versions are Solaris, Linux, and MacOS X.

The UNIX operating system analysis

The kernel

This is called as the hub of the operating system, serving as allocator of time and memory to programs and handling the filestore and communications in response to system calls.

For an instance, in a case that a user runs command “rm myfile”. The shell searches for the file containing the program “rm”, and then requests the kernel via system calls to execute the program “rm” on “myfile”. When the process “rm myfile” gets done, the shell returns the UNIX prompt % to the user, indicating that it is waiting for another command.

The Shell

This serves as an interface between the user and the kernel. When a user logs in, the login program checks the username and password, then start another program called the shell. The shell is a command line interpreter. It interprets the commands the user run and arranges for them to be executed. The commands are the programs to be run. The shell itself has different types of shell with its own set of commands and functions.

Shell Prompt?

The prompt “$” is called the command prompt. While the prompt is being displayed, you can run a command.

Shell Types?

Bourne Shell — $ character is the default prompt.

  • Bourne Shell(sh)
  • Korn shell(ksh)
  • Bourne Again shell(bash)
  • POSIX shell(sh)

C Shell — % character is the default prompt.

  • C shell(csh)
  • TENEX/TOPS C shell(tcsh)

The original Unix shell was made in the mid 19’s by Stephen R. Bourne. Bourne shell was the first shell to show up in Unix world. Bourne shell is commonly installed as /bin/sh on most versions of Unix.

List of Shells in my MacBook Pro Terminal
The Shell that I am using in the terminal

Interactive shell?

This simply means any shell process that you use to type commands and get back output from the commands. That is, a shell with which you interact.

login shell is a kind of interactive shell but commands running in a shell script is a non-interactive shell because it just runs and ends in the script.

The Bourne shell can be used as an interactive shell just like bash or tcsh. Modern shells like bash, zsh, tcsh are more comfortable and convenient for interactive use like command history, auto completion etc.

Login shell?

A login shell is the first process that executes under your user ID when you log in for an interactive session. The login process tells the shell to behave as a login shell with a convention.

Shell Scripts?

It means a list of commands, which are listed in the order of execution with some comments in there preceded by # sign.

Example Script:

#!/bin/sh

This is a statement for alerting systems that a shell script is being started.

#!/bin/bash
pwd
ls

the script above is an sample script that shows full path to the current directory and then list files in the directory.

Shell Script file has “.sh” extension so the file might be test.sh

To execute the written script, we need to actually save the file with .sh extension and then make it executable by a user like $chmod +x test.sh (meaning now test.sh file is available to execute by anyone).

To execute, we do

$./test.sh

I will cover more details about startup loading files when using the shell

Thanks.

Sign up to discover human stories that deepen your understanding of the world.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

김영석
김영석

Written by 김영석

I love problem solving and hate repetition of tedious tasks. I like automating, streamlining, optimizing, things.

No responses yet

Write a response