Monday, April 6, 2009

What is kernel, shell, shell script

Kernel
The linux kernel is the most important part or in order word called the heart of the linux operating system. It is the piece of code that manages both hardware and software components and communicates between them. It manages memory, processors, I/O devices with any applications and decides which applications will use hardware resources.

Shell
On your windows machine you have seen command prompt (command.com or cmd.exe) where you type command like ping, ipconfig etc. Similarly, on linux there is such prompt where you can type command and that prompt is called shell. In order to define shell we can say shell is an interpreter that interprets commands as typed from a keyboard or from a text script.

The shell is provided in order to interact with the computer systems. Shell itself is not part of the kernel, but it uses kernel to executes commands.

Shell interprets user commands, not compile them. It reads commands from the script per line and execute the commands, while a compiler converts a program into machine readable form, an executable file - which may then be used in a shell script.

There are various types of shell and can be broadly defined into four categories.

1)Bourne like shell(sh): Almquist shell (ash), Bourne-Again shell (bash), Debian Almquist shell (dash), Korn shell (ksh), Z shell (zsh) falls into bourne like shell category.

2)C shell like (csh): TENEX C shell (tcsh) falls within this category.

3)Non traditional shell: es shell (es), scheme Shell (scsh) falls within this category.

4)Historical shell: Thompson shell (sh), PWB shell or Mashey shell (sh) falls within this category.

In order to know all available shells in your system issue, cat /etc/shells
On my system,
# cat /etc/shells
/bin/sh
/bin/bash
/sbin/nologin
/bin/tcsh
/bin/csh

To find out current shell you are using issue, echo $SHELL or ps $
On my system,

# ps $$
PID TTY STAT TIME COMMAND
4593 pts/0 Ss 0:00 -bash
# echo $SHELL
/bin/bash

The default shell for a user is mentioned within /etc/passwd file. For example to know the default shell of a user named arju issue,
# cat /etc/passwd |grep arju
arju:x:522:522::/home/arju:/bin/bash

To switch from one shell to another shell just write the name of the shell in the shell prompt.

For example to switch into bash shell issue,
#bash

To switch into TENEX C shell issue,
#tcsh

Shell Script
Shell script is a plain text file which contains a series of commands. In this case instead of running command one by one we can store all commands in a script and we execute the script. It is similar to a batch file in MS-DOS.

Related Documents
Introduction -What is kernel, shell, shell script.
Basic Steps to write a shell script
Variables in shell script
Output text with echo command
Arithmetic operation and expression in shell script with expr
Basic shell programming commands quote, exit and read

No comments:

Post a Comment