Читаем 100 Shell Programs in Unix полностью

V. UNIX ARCHITECTURE

Figure below shows the three layers of UNIX operating system. On the outermost layer sits the user with application programs and other utilities. The kernel interacts with the actual hardware. The shell acts as the command interpreter between the user and the kernel.

The Kernel

At the center of the UNIX onion is a program called the kernel. The kernel of UNIX is the hub of the operating system. The kernel has various functions. It manages files, carries out all the data transfer between the file system and the hardware, and also manages memory. It allocates time and memory too.

The Shell

The shell acts as an interface between the user and the kernel. Shell is an intermediate program that accepts the commands, typed at the terminal and executes them to obtain kernel understandable command set. Important features are given below:

Programming Language Constructs: Shell provides powerful constructs using which exiting commands can be used to frame the job sequences or develop new utilities.

Shell Scripts: Shell commands and constructs are stored in a file, which can later be used to execute these commands like a program. This file is generally called shell script.

Shell Variables: Like other programming language one can define variable in shell program also. These variables are identified by prefixing their names with ‘$’ sign.

Variables can be classified into four categories:

Standard Variables: These are predefined in the system and therefore called built-in-variables. They hold certain system information related to particular user environment.

These are also called environmental variables.

PS1 : Represent the first prompt of the user, Default is ‘$’.

$echo $PS1

[\u@\h \W]\$

$PS1=#

#

PS2 : Represent the second prompt of the user, Default is ‘>’.

$echo $PS2

>

$

Logname: User’s login name

$logname

root

$

Positional Parameters: These are variables which receives their values from command-line as an argument. These are identified by their position on the command line as $0, $1, $2,… where $0 holds name of program and others denote another command-line argument.

Special Shell Variable: These are the variables that hold certain other information such as $$ stores process ID of the current shell, $! Stores process ID of last back ground process.

User Defined Variables: Users may define their own variables either in shell script or at the shell prompts. These variables can have any name except for those described above.

UNIX supports different types of shells. Some of these shells are:

Bourne Shell (sh)

C Shell (csh)

Korn Shell (ksh)

Job Shell (jsh)

VI. UNIX BASIC COMMANDS

A text editor is a program for storing and manipulating information in the computer. Three of the most popular editors in UNIX system are ed, vi and emacs. The ed editor works on any terminal as it takes no advantage of special terminal features.

Vi. Editor

Vi, (stands for Visual Editor,) is one of the most significant tools provided by UNIX and is used to create and edit text files. It is a screen-oriented editor that is extremely fast when scrolling through large documents. It does not support any document formatting like bold/italics, spell checking or any views of a document, as it will look when printed.

Table: Commands for quiting vi

Commands

Functions

  ZZ

Write the buffer to the file and quits vi.

  :wq

Write the buffer to the file and quits vi.

  :w filename

Write the buffer to the file filename (new).

  :q

Quits vi if changes made to the buffer were written to a file.

  :w!

Overwrites the existing file filename with the contents of the buffer.

  :q!

Quits vi whether or not change made to the buffer were written to a file. Does not incorporate changes made to the buffer since the last write (:w) command.

For example, addition of two numbers Steps to write a program

Step-1:

vi prg1

clear

echo “Input Value of a & b :”

read a

read b

c=‘expr $a + $b’

echo $c

Step-2:

(

i

). press Esc

(

ii

). :wq

Step-3:

sh prg1

Result:

Let a = 10

Let b = 12

Output is 22

The reader is motivated to practice the following commands with all possible options

1. The ls command

: ls [option] filename

The ls command lists the names of files in given directory or in current directory if no filename is specified. The names of files are in ascending order.

[Options]: -l : long listing about each file.

-t : files listed in order in which they were last changed, most recent first.

2.

pwd

command — pwd

3.

mkdir

— mkdir

4.

cd

— cd

5.

rmdir

— rmdir

6.

chmod

— To Assign Permissions to files.

UNIX supports two levels of security one is through login and another security is implemented by assigning different types of access permissions to different files.

UNIX divides all users into three categories:

Похожие книги