final project 18.11.10 ppt

15
UNIX Shell UNIX Shell Programming Programming

Upload: soumik-majumder

Post on 08-Apr-2018

221 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: final project 18.11.10 ppt

8/7/2019 final project 18.11.10 ppt

http://slidepdf.com/reader/full/final-project-181110-ppt 1/15

UNIX ShellUNIX Shell

ProgrammingProgramming

Page 2: final project 18.11.10 ppt

8/7/2019 final project 18.11.10 ppt

http://slidepdf.com/reader/full/final-project-181110-ppt 2/15

OUTL

INE

Page 3: final project 18.11.10 ppt

8/7/2019 final project 18.11.10 ppt

http://slidepdf.com/reader/full/final-project-181110-ppt 3/15

What is Shell? 

The shell is both a command languageand a programming language thatprovides an interface to the UNIXoperating system.

Page 4: final project 18.11.10 ppt

8/7/2019 final project 18.11.10 ppt

http://slidepdf.com/reader/full/final-project-181110-ppt 4/15

ABOUT SHELL

Shell is most important program on unixfrom end user stand point

The shell is type of  interpreter 

An interpreter operate a simple loop itaccept command then interprets & execute

the commandacceptcommand

Interpretscommand

Executecommand

displayprompt

Page 5: final project 18.11.10 ppt

8/7/2019 final project 18.11.10 ppt

http://slidepdf.com/reader/full/final-project-181110-ppt 5/15

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 shellsavailable on Unix system like csh, tcsh, sh,

etc.

Etch type of shell support a different typeof command language

Page 6: final project 18.11.10 ppt

8/7/2019 final project 18.11.10 ppt

http://slidepdf.com/reader/full/final-project-181110-ppt 6/15

About Shell Scripting

Shell scripts usually begin with a #! and a shell name

(complete pathname of shell).

±  Pathname of shell be found using the which

command.

±  The shell name is the shell that will execute this script.

� E.g: #!/bin/bash

If no shell is specified in the script file, the default is

chosen to be the currently executing shell.

Different shells have different control

structures

Page 7: final project 18.11.10 ppt

8/7/2019 final project 18.11.10 ppt

http://slidepdf.com/reader/full/final-project-181110-ppt 7/15

Why write shell scripts ?

To avoid repetition

If you do a sequence of steps with standard

Unix commands over and over, then we

write shell scripts to avoid repetitions of 

command.

Or in other words, store all these commands

in a file and execute them one by one.

Page 8: final project 18.11.10 ppt

8/7/2019 final project 18.11.10 ppt

http://slidepdf.com/reader/full/final-project-181110-ppt 8/15

To automate difficult tasks

Many commands have subtle and difficult

options that you don¶t want to figure out or 

remember every time .

Why write shell scripts ?

Page 9: final project 18.11.10 ppt

8/7/2019 final project 18.11.10 ppt

http://slidepdf.com/reader/full/final-project-181110-ppt 9/15

Shell variables The shell provides string-valued variables. Variable

names begin with a letter, digits and underscores.Variables may be given values by writing,

for example,

user=fred box=m000 acct=mh0000

The value of a variable is substituted by preceding itsname with $; for example,

echo $user will echo f  red.

$? 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.

$$ holds theprocess number of this shell.

$! informs the process number of the last process run in

the background

Page 10: final project 18.11.10 ppt

8/7/2019 final project 18.11.10 ppt

http://slidepdf.com/reader/full/final-project-181110-ppt 10/15

$- holds the current shell flags

$MAIL is typically set in the file .profile, in the user's

login directory. 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, by default, `$ '.

$PS2 is the shell prompt when further input is needed, by

default, `> '.

$IFS is the set of characters used by blank interpret ation

Page 11: final project 18.11.10 ppt

8/7/2019 final project 18.11.10 ppt

http://slidepdf.com/reader/full/final-project-181110-ppt 11/15

TYPE OF SHELL In Unix operating system we found 13 types of 

shell. Etch type of shell holds different type of 

command. They are1. The Bourne shell or sh.

2. Almquist shell or ash.

3. DebianAlmquist shell or dash.4. Bourne-again shell or bash.

5. Friendly interactive shell or fish.

6. Korn shell or ksh.

7. C shell or csh .

8. Tenex C shell or tcsh.9. Es shell.

10. Rc shell.

11. Scsh.

12. Stand-alone shell or sash.

13. Z shell or zsh

Page 12: final project 18.11.10 ppt

8/7/2019 final project 18.11.10 ppt

http://slidepdf.com/reader/full/final-project-181110-ppt 12/15

The Bourne shell or sh.

The Bourne shell, or sh, was the default Unix shell of 

Unix Version 7.The binary program of the Bourne shellor a compatible program is located at /bin/sh on most

Unix systems, and is still the default shell for the root

super user on many current Unix implementations.

Page 13: final project 18.11.10 ppt

8/7/2019 final project 18.11.10 ppt

http://slidepdf.com/reader/full/final-project-181110-ppt 13/15

Bourne-again shell or bash.

Bash was created in 1987 by Brian Fox. Bash is a

Unix shell written for the GNU Project. Bash is

the default shell on most Linux systems as well as

on MacO

S X and it can be run on mostU

nix-likeoperating systems.

Page 14: final project 18.11.10 ppt

8/7/2019 final project 18.11.10 ppt

http://slidepdf.com/reader/full/final-project-181110-ppt 14/15

Korn shell or ksh.

It is backwards compatible with theB

ourneshell and includes many features of the C

shell as well, such as a command history.

The main advantage of ksh over the

traditional Unix shell is in its use as aprogramming language

Page 15: final project 18.11.10 ppt

8/7/2019 final project 18.11.10 ppt

http://slidepdf.com/reader/full/final-project-181110-ppt 15/15

C shell or csh.

The C shell (csh) is a Unix shell developed by Bill Joy for 

theIts syntax is modeled after the C programminglanguage. The C shell added many feature improvements

over thethe original C shell is not in wide use on Unix

Bourne shell BSD Unix system.