Команда с конвейером и перенаправлением

В Make-файл , вы обращаетесь к переменной при помощи синтаксиса $ (var_name) . Используя $var_name вызывают первый символ кроме знака доллара $ , открывающая скобка (, или открытая фигурная скобка { рассматривала как имя переменной.

В $now , вы на самом деле получаете содержание переменной $n сопровождаемый литеральной строкой ой .

, Таким образом, вам нужно:

$(now)

для получения содержания переменной, названной теперь .

Также примечание, что now= $ (дата) получают содержание переменной, названной дата вместо результата даты команды . Необходимо использовать функция оболочки :

now=$(shell date)

3
11.05.2018, 11:31
2 ответа
utility1 | utility2 >output

no es equivalente a

( utility1 | utility2 ) >output

sino a

utility1 | { utility2 >output; }

Las dos utilidades se inician prácticamente al mismo tiempo, lo que significa que esperaría que su comando a veces devuelva 3 y otras veces 2.

Ejemplo:

$ { [ -f test ] && echo exists >&2; } | { echo >test; }; rm test
$ { [ -f test ] && echo exists >&2; } | { echo >test; }; rm test
$ { [ -f test ] && echo exists >&2; } | { echo >test; }; rm test
exists
$ { [ -f test ] && echo exists >&2; } | { echo >test; }; rm test
exists
$ { [ -f test ] && echo exists >&2; } | { echo >test; }; rm test
$ { [ -f test ] && echo exists >&2; } | { echo >test; }; rm test

Lo anterior muestra que el archivo creado por el lado derecho de la tubería es a veces detectado por el lado izquierdo de la tubería.

14
27.01.2020, 21:07

golpe de hombre

REDIRECTION
       Before  a  command is executed, its input and output may be redirected using a special notation interpreted by the shell.  Redirection
       may also be used to open and close files for the current shell execution environment.  The following redirection operators may precede
       or appear anywhere within a simple command or may follow a command.  Redirections are processed in the order they appear, from left to
       right.

entonces, cuando ejecuta el comando, se crea el resultado ls _y luego ejecuta el comando ls. Es por eso que la salida viene como 3.

ls | wc -l > ls_result

3
27.01.2020, 21:07

Теги

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