A shell is a user program that allows the user to specify operations in a certain sequence.
As we discussed in last post about what is shell in UNIX. Now we will discuss about all different type of shell available in UNIX.
If all shell available on your system then you can switch between different shells. Following are different types of shells –
Bourne Shell (sh) – Bourne Shell is the original unix shell developed at AT&T by Stephen Bourne. Bourne shell also named as (sh) programming name. It used the symbol $. Bourne shell’s family is bourne, korn shells, bash and zsh .
korn shell (ksh) – korn shell is the unix shell developed by David korn of Bell labs. Is is considered as the family member of Bourne shell as it uses the $ symbol of Bourne shell. It is also names as ksh programmatic ally and it most widely used shell.
Bourne Again Shell (bash) – It is the free version of Bourne shell and comes with all UNIX/Linux systems as free with some additional features like command line editing. Its program name is bash. It can read commands from file called scripts.
Like all Unix shells it supports the following:
- File name wildcarding
- Hear documents
- Command execution
- Variables and control structures for condition testing and iteration
C Shell (sh) – C shell is the UNIX shell created by Bill joy at California university as an alternative to Bourne shell – Unix original shell. C shell along with Bourne and Korn, are there most popular and commonly used shells. csh is the program name for C shell.
Tab C Shell (tcsh) – It is the family member of C shell with additional features like enhanced history substitution to reuse commands, spelling correction and word completion.
Hello World Example
Create a file first.sh
#! /bin/sh // This line tells Unix that the file to be executed by /bin/sh.
echo Hello World
Now run –
Output will be – Hello World
Arithmetic operators are supported by Bourne Shell are –
+ (Addition) Adds values on either side of the operator
– (Subtraction) Subtracts right hand operand from left hand operand
* (Multiplication) Multiplies values on either side of the operator
/ (Division) Divides left hand operand by right hand operand
% (Modulus) Divides left hand operand by right hand operand and returns remainder
= (Assignment) Assigns right operand in left operand
== (Equality) Compares two numbers, if both are same then returns true.
!= (Not Equality) Compares two numbers, if both are different then returns true.
val=`expr $a + $b`
echo "a + b : $val"
val=`expr $a - $b`
echo "a - b : $val"
val=`expr $a \* $b`
echo "a * b : $val"
Working with VI editor – VI is main editor to work on unix systems. There are 3 main command mode on vi editor.
Command Mode – Keys works as command like insert, delete, moving to new line etc. We can not edit or type in command mode.
Insert Mode – To write anything in script, press I or A for insert mode.
Execution Mode – This mode is used to execute that we have done. Like to save changes, first press escape key then type colon and wq.
Vi editor saving and quitting commands:
:w -Save the contents of the file.
:q – Quit from vi editor.
:q! -quit from vi editor by discarding any changes.
:wq -Save the file and quit from the vi editor.
Please correct me, if anything found wrong here. Please comment also for any additional shell type in UNIX.