Студопедия
Случайная страница | ТОМ-1 | ТОМ-2 | ТОМ-3
АрхитектураБиологияГеографияДругоеИностранные языки
ИнформатикаИсторияКультураЛитератураМатематика
МедицинаМеханикаОбразованиеОхрана трудаПедагогика
ПолитикаПравоПрограммированиеПсихологияРелигия
СоциологияСпортСтроительствоФизикаФилософия
ФинансыХимияЭкологияЭкономикаЭлектроника

Key Positions

Читайте также:
  1. Charakterisierung der semantischen Eigenschaften der Kompositionsmitglieder
  2. Club’s positions and Job descriptions
  3. Complete the following letter of enquiry with the correct prepositions.
  4. Complete the sentences with the prepositions below.
  5. Complete this letter of enquiry with the correct prepositions.
  6. Conjunctions and prepositions 1 страница
  7. Conjunctions and prepositions 2 страница

Chair of Telecommunication Networks

 

Nikitchenko V.V., Krasovsky M.L., Yavorskaya O.M.

 

NETWORK OPERATING SYSTEMS

 

Teaching Aid

For training bachelors

In Telecommunication

 

Odessa, 2012

Laboratory work № 1

Command Interpreter csh

 

Goal of work

1.1 To get acquainted with command interpreter for Unix system.

1.2 To get skills of practical work with interpreter csh

 

Key Positions

2.1 Common knowns

 

Even if you operate UNIX system with help of X-Window graphical interface, still you will need to deal with command interpreter. It gives flexibility, that is necessary for solving the most difficult problems, but requires certain experience at the same time. As known, interpreter is a command-line interface, that is very different from graphical environments like Windows or Mac OS. Sometimes interpreter is called shell. This term is used in UNIX systems for description of different operation system work levels, in architecture of which such functions are defined: internal, automated and external that are run by user. Providing of safe and structured access to the kerrel is one of the interpreter tasks. It perceives user`s commands and with the help of system core functions converts it into the processes, that works with files and devises. It prevents execution of unreliable code that can cause core failure and also makes searching and programs running in system easier.

In practical sence interpreter is a program that can cause new processes. It runs with a system during every registration in it, displays command-line invitation, executes user commands and finishes its work after the exit from the system.

 

2.2 Command Interpreter csh

 

Csh command is a command language`s interpreter.It starts with execution of command from. cshrc file in home catalog of user which caused it. If it is interpreter of log in, it also executes commands from .login file. In the case of normal functioning, shell interpreter begins command reading from terminals and outputs % sign as invitation. Then command interpreter numerous times executes next operations: reading of logging in row and output it in words. Sequence that was received from words inserts in command prehistory list and then is analyzed syntactically. After this, at last, every command from current row is executed. When interpreter shell of log in completes its execution, it executes commands from. logout file from input user catalog.

Interpreter separates input rows on words, considering that they separates from each other with spaces and tabulation signs, taking into account next exceptions. Symbols &, |,;, <, >, (,) form separate words. Separate words form such pairs of double symbols as &&, ||, << or >>. Such methasymbols of syntactic analyzer can be the part of other words or their special task can be cancelled by previous symbol \. Sign of new row with symbol \ is equivalent to space.

Moreover, rows that enclosed in pairs of quotes:`, ‘, or “ forms parts of word; methasymbols in such rows that include spaces and tabulation signs doesn`t form separate words. Inside pairs that consist of symbols \ or “, sign of new row with a priori sign \ represents really symbol of new row.

When input data for interpreter inputs not from the terminal, symbol # points that comments that continue until the end of input row are situated in the row. This symbol has no special task if it has a priori sign \ and if it is situated inside the quotes `, ‘, or “.

 

Command Line

 

Interpreter when he receives command line, executes some changes with it, namely:

-reveals alias;

-reveals methasymbols (*,?, [, ], ~, {, });

-substitutes variables shell;

-executes command if it is built-in command of interpreter or starts process if command is external.

Lets analyze operations on stages.

Alias. Built-in command alias allows to define commands` alias. Example:

# alias mycat ‘cat | more’

 

Defines mycat as aliasof line cat | more. That`s why you can use command mycat further and it will be revealed by interpreter everywhere you will use it. This is the way of defining of short names for long multiple commands.

Built-in command unalias mycat destroys alias mycat that was known earlier.

Methasymbols. Methasymbols allows to write shortly entire lists of words (mostly file names). Csh considers word that includes methsymbols as a template for making a list of file names:

- in template it replaces any sequence of symbols. For example m* will reveal in list of all files that begin from letter m. There exist small exception from this rule: just * lowers in list suchfiles that have names beginning with point;

-? replaces one of the symbols. For example m? will rexeal in the list of all file names that begins with m and consists only two leters;

- [.-.] allows to show interval for substituting symbol. For example m[a-e] will be revealed in ma mb mc me;

- {…,…} allows to list words for substitution. For example m{red,blue,green} will be revealed in mred mblue mgreen;

- At last tilde allows to show home catalog of user:

~name/ is equivalent to directory of full path in home catalog of user name (For example, /usrl/name/);

~/ is equivalent to directory of full path in your own home catalog.

 

2.3 Variables of mediums

 

Variables of mediums contains values that are available for run programs during whole work session. Moreover these variables controls some program actions. For example utility chfn runs text editor that is situated in variable of medium EDITOR and variable TERM informs interpreter how it should format text for correct displaying on the screen. Variable BLOCKSIZE controls format of output numbers by utilities du and df: kilobytes, semikilobytes, etc. Program is not required to be initial command interpreter to contact variables of medium- every program has access to them same as program that installed them.

Variables of medium list can be viewed with help of command printenv:

 

# printenv

PATH=/sbin:/usr/sbin:/bin:/usr/bin:/usr/local/bin:/usr/contrib/bin:/usr/XllR6/bin:.

MAIL=/var/mail/frank

BLOCKSIZE=lk

FTP_PASSIVE_MODE=YES

USER=frank

LOGNAME=frank

HOME=/home/frank

SHELL=/bin/tcsh

SSH_CLIENT=192.168.173.230 50095 22

SSH_TTY=/dev/ttyp0

TERM=vt100

HOSTTYPE=FreeBSD

VENDOR=intel

OSTYPE=FreeBSD

MACHTYPE=i386

SHLVL=1

PWD=/home/frank

GROUP=users

HOST=stripes.somewhere.com

REMOTEHOST=192.168.173.230

PATHSET=true

EDITOR=vi

Visual=pico

 

To set up variable COLOR with value gold in csh next command is use:

 

# setenv COLOR gold

 

Note that variable of medium must have value. It can not be equal to null or not defined at all.

 

 

2.4 Variables of command interpreter

 

There exist another set of variables that are available during work session. These variables of command interpreter are used only during current session and does not connected with other processes. They are available only for Interpreter process. In terms of programming Variables of interpreter are local and variables of medium- global, that are inherited by all programs.

Variables за interpreter in csh should belong to lower register. It can be watched through with help of command set. Setting of interpreter variables in csh is made also with help of command set. In csh interpreter variable can be defined without assigning of value:

 

# set history 100

# set noclobber

 

With help of unset variable can be deleated:

 

# unset autologout

 

2.5 Interpreter initialization files

It's time to discuss how the interpreter is configured. It allows you to create aliases to simplify the commands, automatically run certain programs when you log on, set variables of medium, etc. For these tasks the initialization and configuration files that exist at the global and user levels correspond.
In csh such files are used to configure.cshrc,.login and.logout.
The first file, which is drawn by csh when you start is configuration system-level file /etc/csh/.cshrc immediately followed by an appeal to /etc/csh.login. Note that on FreeBSD, there exist both files, but their contents are commented out (see Listing 1).
Listing 1 global file /etc/csh.cshrc and /etc/csh.login.

 

#cat /etc/csh.cshrc

# $FreeBSD: src/etc/csh. cshrc, v 1.3 1999/08/27 23:23:40 peter Exp $

# System-level file.cshrc for csh(l).

# cat /etc/csh.login

# $FreeBSD: src/etc/csh. login, v 1.19.2.1 2000/07/31 20:13:26 rwatson AExp $

# System-level file.login for csh(l).

# setenv BLOCKSIZE К

#

# to set languages and code pages refer to

# login.conf(5), and to options charset and lang.

# Full locale-page is situated in s /usr/share/locale/*

#

# Reading of system messages

# msgs –f

# Enabling of therminal messages

# mesg v

 

Listing shows that these files do not execute any function, but they can be used. Any change made to these files, for example, the inclusion of terminal messages, is a global and canceled only if the user configuration files corresponding option is set differently. The configuration files are similar to the system user, but addressing to them is performed a little later. These files are situated in initial user catalog:. cshrc and .login.

File. cshrc (its source is /usr/share/skel/dot.cshrc) by default performs setting of medium of command interpreter. It creates several alias:

 

alias h history 25

alias j jobs -1

alias la ls –a

alias lf ls –FA

alias ll ls –lA

 

set paths of program searching:

 

set path=(/sbin /bin /usr/sbin /usr/bin /uar/games /usr/local/ *sbin /usr/local/bin /usr/XHR6/bin $HOME/bin)

 

and also sets variables of mediums,that control some system tasks behavior:

 

setenv EDITOR vi

setenv PAGER more

setenv BLOCKSIZE K

 

This configuration file performs some other functions. Review file. cshrc from your initial catalog on your computer.
In the file. login, which is performed the next, the user places the programs that should run when it is registered in the system. For example, the default file .login (from / usr / share / skel / dot.login) includes a program fortune and a conditional statement, but this line is commented out:

 

# Message output during log in:

# [ -х /usr/games/fortune ] && /usr/games/fortune -s

 

The administrator or the user itself can specify the processes that should run when you log off. For example, it could be a script that deletes all temporary files in the directory / tmp, owned by the user. The script is enough to include in the file / etc / csh.logout, that don`t have a default executable content:

 

#cat /etc/csh-logout

# SFreeBSD: src/etc/csh.logout,v 1.3 1999/08/27 23:23:41 peter Exp $

#

# System-level file.logout for csh(l).

 

When the process exits the system also turn to file .logout in the initial user catalog, if it is there. By default, this file is not installed.
All these files are executed when you start csh as the primary interpreter. However, the command interpreter can be launched and in other circumstances. For example, to run the script (if desired interpreter specified directly in the line of the script). In this case the files.login and.logout (as well as their equivalents system-level) are ignored.

 

2.6 Configuring of the medium of command interpreter

We have already seen how to configure the medium of command interpreter using its configuration files. This is an excellent example of extending its functionality. It should be noted that there are additional opportunities, examples of which are not represented in the configuration files by default. Lets consider how they are implemented in csh. In most cases, it is built-in commands that can run either directly from a command line or in a configuration file interpreter.
The interpreter can change the appearance of command line. This is achieved by setting the variable prompt: the output of any command can be used by entering it in the reverse apostrophe, as is done for example in scripts in Perl. In addition, you can display the variable containing “the number "command in history. It uses the symbol!. Below is a fairly complex example, which used many of the properties, including the use of sed (stream editor - word processor that handles blocks of text in non-interactive mode) to reduce the host name to its first element:

 

# set promt =”{ `whoami `@`hostname | sed `s/\..*//’`:!} “

{ root@www:23}

 

At the command line, it is convenient to display the directory in which currently resides user, using the result of the command pwd:

 

# set promt=”{ `pwd`:!} “

{ root:24}

 

Setting the search path commands in csh also involves assigning value to a variable environment. To an array of values enclosed in brackets, you can not add value "on the way." You need to add a new element to a string, and then restart the command set, which is why it is best to configure the way in one of the configuration script, and not directly from the command line. The syntax is a bracketed list of paths separated by spaces:

 

set path = (/sbin /usr/sbin /bin /usr/bin /usr/local/bin /usr/ contrib/bin /usr/XHR6/bin /usr/local/sbin /usr/games /usr/local/ mystuff)

 

Another useful tool is the built-in stty. It allows you to override the code table of symbols. This is required in situations where a terminal program sends to other programs unexpected symbols, such as confusion between delete and backspace or newline symbols. You must first view the current settings:

 

# stty –a

Speed 38400 baud; 60 rows; 80 columns;

1flags: icanon isig iexten echo echoe -echok- echoke -echonl echoctl -echoprt -altwerase -noflsh -tostop -flusho pendin -nokerninfo -extproc

iflags: -istrip icrnl -inlcr -igncr ixon -ixoff ixany imaxbel -ignbrk brkint -inpck -ignpar -parmrk

oflags: opost onlcr -oxtabs

cflags: cread cs8 -parenb -parodd hupcl -clocal -cstopb -crtscts -dsrflow -dtrflow -mdmbuf

cchars: discard = A0; dsusp = AY; eof = AD; eol =<undef>;

eol2=<undef>; erase= ^?;intr= ^?C; kill= ^U;

lnext ^V; min= 1; quit= ^\;reprint = ^R;

start= ^Q; status= ^T;stop= ^S; susp= ^Z;

time = 0; werase = ^W;

 

Now if you want to set symbol erase as ^H,you should use command:

 

# stty erase ^H

 

In addition, you can enable watch mode when the system informs about the users registered in it, and used pseudotherminals. This is achieved by a sequence of commands:

 

set watch= (1 any any)

set who="%n has %a %1 from %M."

 

Finally, if the setting of variables was performed by editing the configuration scripts do not need to go out and re-register it for the settings to take effect, enough to reread the configuration of built-in command rehash.

 


Дата добавления: 2015-11-14; просмотров: 34 | Нарушение авторских прав


<== предыдущая страница | следующая страница ==>
Электронная цифровая подпись. Основания использования.| Людська цивілізація на території України

mybiblioteka.su - 2015-2024 год. (0.024 сек.)