UNIX Shell Programming


.What is Shell?  The shell is both a command language and a programming language that provides an interface to the UNIX operating system.

ABOUT SHELL  Shell is most important program on unix from end user stand point  The shell is type of interpreter  An interpreter operate a simple loop it accept command then interprets & execute the command display prompt accept command Execute command Interprets command .

etc.Shell Script  A shell script is simply ordinary text file containing a series of commands in a shell command language  There are many different type of shells available on Unix system like csh. tcsh. sh.  Etch type of shell support a different type of command language .

± The shell name is the shell that will execute this script.g: #!/bin/bash  If no shell is specified in the script file.  Different shells have different control structures . the default is chosen to be the currently executing shell. ± Pathname of shell be found using the which command.About Shell Scripting  Shell scripts usually begin with a #! and a shell name (complete pathname of shell). ‡ E.

 Or in other words. store all these commands in a file and execute them one by one. then we write shell scripts to avoid repetitions of command.Why write shell scripts ? To avoid repetition  If you do a sequence of steps with standard Unix commands over and over. .

.Why write shell scripts ? To automate difficult tasks  Many commands have subtle and difficult options that you don¶t want to figure out or remember every time .

 $! informs the process number of the last process run in the background . echo $user will echo fred.  $$ holds theprocess number of this shell. digits and underscores.  $? Is used Testing the value of return codes is dealt with later under if and while commands.  $# is use to check the number of parameters. Variables may be given values by writing.Shell variables  The shell provides string-valued variables. for example. user=fred box=m000 acct=mh0000  The value of a variable is substituted by preceding its name with $. for example. Variable names begin with a letter.

 $. by default. in the user's login directory. by default. `> '. For example. MAIL=/usr/mail/fred  $HOME is the default argument for the cd command  $PATH consists of directory names separated For example. `$ '. PATH=:/usr/fred/bin:/bin:/usr/bin  $PS1 is the primary shell prompt string.  $IFS is the set of characters used by blank interpretation .holds the current shell flags  $MAIL is typically set in the file .  $PS2 is the shell prompt when further input is needed.profile.

2. 12. Bourne-again shell or bash. 6. The Bourne shell or sh. Es shell. 13. Korn shell or ksh. Almquist shell or ash. Tenex C shell or tcsh. C shell or csh . Friendly interactive shell or fish. 3. 4. 10. Etch type of shell holds different type of command. 9. 7. 5.TYPE OF SHELL  In Unix operating system we found 13 types of shell. Stand-alone shell or sash. They are 1. Scsh. 8. Debian Almquist shell or dash. Z shell or zsh . Rc shell. 11.

.The Bourne shell or sh.The binary program of the Bourne shell or a compatible program is located at /bin/sh on most Unix systems. was the default Unix shell of Unix Version 7. and is still the default shell for the root super user on many current Unix implementations. or sh.  The Bourne shell.

Bash is a Unix shell written for the GNU Project. .Bourne-again shell or bash. Bash is the default shell on most Linux systems as well as on Mac OS X and it can be run on most Unix-like operating systems.  Bash was created in 1987 by Brian Fox.

Korn shell or ksh. such as a command history. The main advantage of ksh over the traditional Unix shell is in its use as a programming language .  It is backwards compatible with the Bourne shell and includes many features of the C shell as well.

 The C shell (csh) is a Unix shell developed by Bill Joy for theIts syntax is modeled after the C programming language.C shell or csh. The C shell added many feature improvements over thethe original C shell is not in wide use on Unix Bourne shell BSD Unix system. .

Sign up to vote on this title
UsefulNot useful