Являются ли /dev/{udp,tcp} стандартизированными или доступными везде?

Если все строки правильно отформатированы, то

awk -F: '{print >int($2/15)*15 ".log"}' inputfile

создаст файлы 0.log, 15.log, 30.log и 45.log.

Он работает путем разделения с использованием двоеточия в качестве разделителя, поэтому второе поле дд мм гггг чч: мм: сс, xxx составляет мм . Мы делим это на 15, берем целую часть и умножаем на 15, чтобы получить значение мм в начале четверти часа. Затем мы добавляем строку «.log» . Затем мы говорим awk напечатать текущую строку в этом файле.

17
21.09.2016, 01:52
2 ответа

Это функция оболочки , а не операционной системы.

Так, например, в Solaris 10 с ksh88 в качестве оболочки:

% cat < /dev/tcp/localhost/22
ksh: /dev/tcp/localhost/22: cannot open

Однако, если мы переключимся на bash :

% bash
bash-3.2$ cat < /dev/tcp/localhost/22
SSH-2.0-Sun_SSH_1.1.5

Итак bash интерпретирует / dev / tcp , а ksh88 - нет.

В Solaris 11 с ksh93 в качестве оболочки:

% cat < /dev/tcp/localhost/22
SSH-2.0-Sun_SSH_2.2

Итак, мы видим, что это очень зависит от используемой оболочки.

29
27.01.2020, 19:47

Чтобы добавить, из узла Bash Info:

Bash handles several filenames specially when they are used in redirections, as described in the following table. If the operating system on which Bash is running provides these special files, bash will use them; otherwise it will emulate them internally with the behavior described below.

'/dev/fd/FD' If FD is a valid integer, file descriptor FD is duplicated.

'/dev/stdin' File descriptor 0 is duplicated.

'/dev/stdout' File descriptor 1 is duplicated.

'/dev/stderr' File descriptor 2 is duplicated.

'/dev/tcp/HOST/PORT' If HOST is a valid hostname or Internet address, and PORT is an integer port number or service name, Bash attempts to open the corresponding TCP socket.

'/dev/udp/HOST/PORT' If HOST is a valid hostname or Internet address, and PORT is an integer port number or service name, Bash attempts to open the corresponding UDP socket.

5
27.01.2020, 19:47

Теги

Похожие вопросы