• No results found

shell interpreter.ppt

N/A
N/A
Protected

Academic year: 2020

Share "shell interpreter.ppt"

Copied!
13
0
0

Loading.... (view fulltext now)

Full text

(1)

SHELL INTERPRETER

(2)

UNIX SHELL INTERPRETERS

C

S

C

I 3

30

- T

he

U

N

IX

S

ys

te

m

A

Unix shell

is a

command-line interpreter

or

shell

that provides a

traditional Unix-like command line user interface. Users direct the

operation of the

computer

by entering commands as text for a

command line interpreter

to execute, or by creating text scripts of one

or more such commands. Users typically interact with a Unix shell

using a

terminal emulator

, however, direct operation via serial

hardware connections, or networking session, are common for server

systems.

(3)

CONT…

 The most generic sense of the term shell means any program that users

employ to type commands. A shell hides the details of the underlying operating system and manages the technical details of the operating system kernel interface, which is the lowest-level, or "inner-most" component of mo

 In Unix-like operating systems, users typically have many choices of

command-line interpreters for interactive sessions. When a user logs in to the system interactively, a shell program is automatically executed for the duration of the session. The type of shell, which may be customized for each user, is typically stored in the user's profile, for example in the local

passwd file or in a distributed configuration system such as NIS or LDAP; however, the user may execute any other available shell interactively.

C

S

C

I 3

30

- T

he

U

N

IX

S

ys

te

(4)

 The Unix shell is both an interactive command language as well as a scripting programming language, and is used by the operating system as the facility to control (shell script) the execution of the system.[1] Shells

created for other operating systems often provide similar functionality.

 On hosts with a windowing system, like OS X, some users may never

use the shell directly. On Unix systems, the shell has historically been the implementation language of system startup scripts, including the program that starts a windowing system, configures networking, and many other essential functions. However, some system vendors have replaced the traditional shell-based startup system (init) with different approaches, such as systemd.

C

S

C

I 3

30

- T

he

U

N

IX

S

ys

te

m

(5)

UNIX SHELL INTERPRETERS

C

S

C

I 3

30

- T

he

U

N

IX

S

ys

te

(6)

INTRODUCTION TO SHELL

PROGRAMMING

Shell programming is one of the most powerful

features on any UNIX system

If you cannot find an existing utility to

accomplish a task, you can build one using a shell

script

C

S

C

I 3

30

- T

he

U

N

IX

S

ys

te

(7)

SHELL PROGRAM STRUCTURE

A shell program contains high-level

programming language features:

Variables for storing data

Decision-making control (e.g. if and case statements)

Looping abilities (e.g. for and while loops)

Function calls for modularity

A shell program can also contain:

UNIX commands

Pattern editing utilities (e.g. grep, sed, awk)

C

S

C

I 3

30

- T

he

U

N

IX

S

ys

te

(8)

YOUR SHELL PROGRAMMING

LIBRARY

Naming of shell programs and their output

Give a meaningful name

Program name example: findfile.csh

Do not use: script1, script2

Do not use UNIX command names

Repository for shell programs

If you develop numerous shell programs, place them

in a directory (e.g. bin or shellprogs)

Update your path to include the directory name

where your shell programs are located

C

S

C

I 3

30

- T

he

U

N

IX

S

ys

te

(9)

STEPS TO CREATE SHELL PROGRAMS

Specify shell to execute program

Script must begin with #! (pronounced “shebang”)

to identify shell to be executed

Examples:

#! /bin/sh

(defaults to bash)

#! /bin/bash

#! /bin/csh

#! /usr/bin/tcsh

Make the shell program executable

Use the “chmod” command to make the

program/script file executable

C

S

C

I 3

30

- T

he

U

N

IX

S

ys

te

(10)

FORMATTING SHELL PROGRAMS

Formatting of shell programs

Indent areas (3 or 4 spaces) of programs to indicate

that commands are part of a group

To break up long lines, place a \ at the end of one

line and continue the command on the next line

Comments

Start comment lines with a pound sign (#)

Include comments to describe sections of your

program

Help you understand your program when you look at

C

S

C

I 3

30

- T

he

U

N

IX

S

ys

te

(11)

STEPS OF PROGRAMMING

Guidelines:

use good names for

script

variables

use comments

lines start with #

use indentation to

reflect logic and

nesting

C

S

C

I 3

30

- T

he

U

N

IX

S

ys

te

(12)

EXAMPLE: “HELLO” SCRIPT

#! /bin/csh

echo "Hello $USER"

echo "This machine is `uname -n`"

echo "The calendar for this month is:"

cal

echo "You are running these processes:"

ps

C

S

C

I 3

30

- T

he

U

N

IX

S

ys

te

(13)

EXAMPLE SCRIPT OUTPUT

% chmod u+x hello % ./hello

Hello ege!

This machine is turing

The calendar for this month is February 2008

S M Tu W Th F S 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28

You are running these processes: PID TTY TIME CMD

C

S

C

I 3

30

- T

he

U

N

IX

S

ys

te

References

Related documents

The primary objective of this research was not necessarily to “fix” or remedy specific leadership issues or capability gaps. Instead, this research described why leadership

Leaving the village on the E road (the 10 o’clock turn on the roundabout), there is on the left a large late 19 th /early 20 th c. Astvatsatsin church, built on earlier

While the point of SSS is to allow individuals to assess their own status, it is likely that our sample (and probably the population) has a somewhat unbalanced opinion of status,

Data on all new births with cleft lip and palate in Taiwan from January 1994 to December 2013 were collected from two main centers in the hospitals: The Chang Gung Memorial

• explain the objectives and basic structure of cost accounting and profit centre accounting, and give reasons why cost awareness and entrepreneurial thinking are necessary..

Respondents in Benbecula, Donegal and Kirkwall also spoke of the importance of their local airport in providing ‘lifeline’ services, particularly in terms of patient travel

This paper has sought to examine family and community life in Malta from the mid- seventeenth century to the middle of the eighteenth through a sample of case

2 of research on six major areas (age, gender, motivation, intelligence, aptitude and personality) in the field of individual differences, as well as the most