What is Shell
Whenever you login to a Unix system you are placed in a program called the shell. The shell acts as a command interpreter; it takes each command and passes it to the operating system kernel to be acted upon. It then displays the results of this operation on completion on your screen.
There are different Flavour of shell in Unix
Finding out which shell you are using Information about which shell you are using is held in the SHELL environment variable. The command echo $SHELL displays the value of this variable.This displays the default shell of the system. You can change the shell though in the script you execute.You can identify which shell you are presently using from the last part of the pathname.
|Bourne shell||This is the original Unix shell written by Steve Bourne of Bell Labs. It is available on all UNIX systems.
Below is written in the beginning of shell scripts to specify the shell to use for the scripts. The default prompt on the Unix for this is $
|C shell||This shell was written at the University of California, Berkeley. It provides a C-like language with which to write shell scripts – hence its name.The default prompt on the Unix for this is %
Below is written in the beginning of shell scripts to specify the shell to use for the scripts
|Korn shell||This shell was written by David Korn of Bell labs. It is now provided as the standard shell on Unix systems. It provides all the features of the C shell with a shell programming language similar to that of the original Bourne shell. It is the most efficient shell. Consider using this as your standard interactive shell.The default prompt on the Unix for this is $Below is written in the beginning of shell scripts to specify the shell to use for the scripts
What is shell Scripts:
A shell script is a collection of command which are executed in a order given. There are conditional statement and looping also available like if ,while which helps in finding if a particular value is greater than another value .
To write any comments in the shell scripts ,it has to be written with # preceded
# Auther of the script is
There are some variables which are set internally by the shell and which are available to the user. They are given below in the table.
|$1 – $9||these variables are the positional parameters.|
|$0||the name of the command currently being executed.|
|$#||the number of positional arguments given to this invocation of the shell.|
|$?||the exit status of the last command executed is given as a decimal string. When a command completes successfully, it returns the exit status of 0 (zero), otherwise it returns a non-zero exit status.|
|$$||the process number of this shell – useful for including in
filenames, to make them unique.
|$!||the process id of the last command run in the background.|
|$*||a string containing all the arguments to the shell, starting at $1.|
Shell scripts and functions are both interpreted. This means they are not compiled.
Commands in Shell
All shells have a number of built-in commands which are executed in the shell’s own process like echo ,cd .
When you enter a command, the shell checks to see, if the command is a shell built-in such as echo or cd ,it is directly interpreted by the shell.
if the command begins with a / shell assumes that the command is the absolute path name of an executable error occurs if the executable is not found.
if not built-in and not a full pathname shell searches the directories in the PATH from left to right for the executable.Current working directory may not be in PATH
If PATH is empty or is not set, only the current working directory is searched for the executable
Unix commands are executable binary files located in directories with the name bin (for binary). Many of the commands that you use are located in the directory /usr/bin.
A typical value for the PATH variable might be: