Добавил:
Upload Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
3_4_format.doc
Скачиваний:
0
Добавлен:
01.05.2025
Размер:
94.21 Кб
Скачать

2.3 Variable noclobber

If the variable noclobber installed, shell does not allow to destroy an existing file, unless explicitly stated otherwise removing it with an exclamation point after the redirection operator for C shell or a vertical line in ksh and bash. Table. 20 shows an example of setting a variable noclobber.

Table 20 - Example of setting a variable noclobber

For C shell and tcsh

For ksh and bash

% set noclobber

% ls

filea fileb

% program > fi.leb

fileb: File exists.

% Program>! Fileb

%

$ Set-o noclobber

$ ls

filea fileb

$ program> fileb

fileb: fileb: Cannot clobber existing file

$ program> fileb

Program tee is writing output data to a file and simultaneously send them to the standard output. You may need to collect output data from several teams and in turn send them to the same file by using the command tee. The obvious solution to this problem - the use of option - a.

$ command 1 | tee file

$ command 2 | tee –a file

$ command 3 | tee –a file

A simpler way to solve is the following;

$ (command- am1

>command 2

  • command 3) | tee file

With the help of the operators () joining Imprint three teams. These data are then transmitted to a team - tee. The result of processing is the same, but in the second case used in the two channels and two smaller programs tee and one generated by the interpreter shell more.

Note: noclobber is not an environment variable, so each new instance of the shell will inherit it. Consequently, the regime noclobber always been installed, insert the command contained in the examples set in the configuration file his interpreter shell.

2.4 Device /dev/null

The device /dev/null is not a regular file, although it can be used as such. This is a special device in the system of UNIX (not physical), which "absorbs" any writes the text. When reading the text of the device, it returns end of file (a file of zero length).

This device is needed for:

  • purification of another file (copy the file / dev / null on top of another file);

  • the hidden work of the program by redirecting its output to this device. For example, you run the program in the background and do not want it to be disturbed: % program > /dev/null.

This standard output is redirected to the program, but in case of error messages about them will come to the terminal;

  • to respond to the programs, ask many questions when it is known that in response to each question, simply press [RETURN]. In many cases, you can redirect standard input from the device /dev/null. % program < dev/null

  • when the program requires another file, and you do not want to read or write this file. For example, grep will not display the file name, in which it found a match if the command line does not contain at least two names. When using wildcards in the directory where it can be only one appropriate file, and enter / dev / null, so the program grep is always looking through more than one file. % grep «string» * dev/null

Соседние файлы в предмете [НЕСОРТИРОВАННОЕ]