{"id":195152,"date":"2013-09-25T13:23:04","date_gmt":"2013-09-25T09:23:04","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=195152"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=195152","title":{"rendered":"<span class=\"post_title\">Linux pipes tips &#038; tricks<\/span>"},"content":{"rendered":"<div class=\"content html_format\">\n<h4>Pipe \u2014 \u0447\u0442\u043e \u044d\u0442\u043e?<\/h4>\n<p>  Pipe (\u043a\u043e\u043d\u0432\u0435\u0435\u0440) \u2013 \u044d\u0442\u043e \u043e\u0434\u043d\u043e\u043d\u0430\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u043d\u044b\u0439 \u043a\u0430\u043d\u0430\u043b \u043c\u0435\u0436\u043f\u0440\u043e\u0446\u0435\u0441\u0441\u043e\u0440\u043d\u043e\u0433\u043e \u0432\u0437\u0430\u0438\u043c\u043e\u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044f. \u0422\u0435\u0440\u043c\u0438\u043d \u0431\u044b\u043b \u043f\u0440\u0438\u0434\u0443\u043c\u0430\u043d <a href=\"http:\/\/ru.wikipedia.org\/wiki\/%D0%9C%D0%B0%D0%BA%D0%B8%D0%BB%D1%80%D0%BE%D0%B9,_%D0%94%D1%83%D0%B3%D0%BB%D0%B0%D1%81\">\u0414\u0443\u0433\u043b\u0430\u0441\u043e\u043c \u041c\u0430\u043a\u0438\u043b\u0440\u043e\u0435\u043c<\/a> \u0434\u043b\u044f \u043a\u043e\u043c\u0430\u043d\u0434\u043d\u043e\u0439 \u043e\u0431\u043e\u043b\u043e\u0447\u043a\u0438 Unix \u0438 \u043d\u0430\u0437\u0432\u0430\u043d \u043f\u043e \u0430\u043d\u0430\u043b\u043e\u0433\u0438\u0438 \u0441 \u0442\u0440\u0443\u0431\u043e\u043f\u0440\u043e\u0432\u043e\u0434\u043e\u043c. \u041a\u043e\u043d\u0432\u0435\u0439\u0435\u0440\u044b \u0447\u0430\u0449\u0435 \u0432\u0441\u0435\u0433\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0442\u0441\u044f \u0432 shell-\u0441\u043a\u0440\u0438\u043f\u0442\u0430\u0445 \u0434\u043b\u044f \u0441\u0432\u044f\u0437\u0438 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u0438\u0445 \u043a\u043e\u043c\u0430\u043d\u0434 \u043f\u0443\u0442\u0435\u043c \u043f\u0435\u0440\u0435\u043d\u0430\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u0432\u044b\u0432\u043e\u0434\u0430 \u043e\u0434\u043d\u043e\u0439 \u043a\u043e\u043c\u0430\u043d\u0434\u044b (stdout) \u043d\u0430 \u0432\u0445\u043e\u0434 (stdin) \u043f\u043e\u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0439, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f \u0441\u0438\u043c\u0432\u043e\u043b \u043a\u043e\u043d\u0432\u0435\u0435\u0440\u0430 \u2018|\u2019:  <\/p>\n<pre><code class=\"bash\">cmd1 | cmd2 | .... | cmdN <\/code><\/pre>\n<p>  \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440:  <\/p>\n<pre><code class=\"bash\">$ grep -i \u201cerror\u201d .\/log | wc -l 43 <\/code><\/pre>\n<p>  grep \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u0442 \u0440\u0435\u0433\u0438\u0441\u0442\u0440\u043e\u043d\u0435\u0437\u0430\u0432\u0438\u0441\u0438\u043c\u044b\u0439 \u043f\u043e\u0438\u0441\u043a \u0441\u0442\u0440\u043e\u043a\u0438 \u201cerror\u201d \u0432 \u0444\u0430\u0439\u043b\u0435 log, \u043d\u043e \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u043f\u043e\u0438\u0441\u043a\u0430 \u043d\u0435 \u0432\u044b\u0432\u043e\u0434\u0438\u0442\u0441\u044f \u043d\u0430 \u044d\u043a\u0440\u0430\u043d, \u0430 \u043f\u0435\u0440\u0435\u043d\u0430\u043f\u0440\u0430\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043d\u0430 \u0432\u0445\u043e\u0434 (stdin) \u043a\u043e\u043c\u0430\u043d\u0434\u044b wc, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0432 \u0441\u0432\u043e\u044e \u043e\u0447\u0435\u0440\u0435\u0434\u044c \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u0442 \u043f\u043e\u0434\u0441\u0447\u0435\u0442 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u0430 \u0441\u0442\u0440\u043e\u043a.<\/p>\n<h4>\u041b\u043e\u0433\u0438\u043a\u0430<\/h4>\n<p>  \u041a\u043e\u043d\u0432\u0435\u0435\u0440 \u043e\u0431\u0435\u0441\u043f\u0435\u0447\u0438\u0432\u0430\u0435\u0442 \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u043e\u0435 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0435 \u043a\u043e\u043c\u0430\u043d\u0434 \u0441 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c \u0431\u0443\u0444\u0435\u0440\u0438\u0437\u0430\u0446\u0438\u0438 \u0432\u0432\u043e\u0434\u0430\/\u0432\u044b\u0432\u043e\u0434\u0430. \u0422\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c \u0432\u0441\u0435 \u043a\u043e\u043c\u0430\u043d\u0434\u044b \u0432 \u043a\u043e\u043d\u0432\u0435\u0439\u0435\u0440\u0435 \u0440\u0430\u0431\u043e\u0442\u0430\u044e\u0442 \u043f\u0430\u0440\u0430\u043b\u043b\u0435\u043b\u044c\u043d\u043e, \u043a\u0430\u0436\u0434\u0430\u044f \u0432 \u0441\u0432\u043e\u0435\u043c \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0435.<\/p>\n<p>  \u0420\u0430\u0437\u043c\u0435\u0440 \u0431\u0443\u0444\u0435\u0440\u0430 \u043d\u0430\u0447\u0438\u043d\u0430\u044f \u0441 \u044f\u0434\u0440\u0430 \u0432\u0435\u0440\u0441\u0438\u0438 2.6.11 \u0441\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 65536 \u0431\u0430\u0439\u0442 (64\u041a\u0431) \u0438 \u0440\u0430\u0432\u0435\u043d \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u0435 \u043f\u0430\u043c\u044f\u0442\u0438 \u0432 \u0431\u043e\u043b\u0435\u0435 \u0441\u0442\u0430\u0440\u044b\u0445 \u044f\u0434\u0440\u0430\u0445. \u041f\u0440\u0438 \u043f\u043e\u043f\u044b\u0442\u043a\u0435 \u0447\u0442\u0435\u043d\u0438\u044f \u0438\u0437 \u043f\u0443\u0441\u0442\u043e\u0433\u043e \u0431\u0443\u0444\u0435\u0440\u0430 \u043f\u0440\u043e\u0446\u0435\u0441\u0441 \u0447\u0442\u0435\u043d\u0438\u044f \u0431\u043b\u043e\u043a\u0438\u0440\u0443\u0435\u0442\u0441\u044f \u0434\u043e \u043f\u043e\u044f\u0432\u043b\u0435\u043d\u0438\u044f \u0434\u0430\u043d\u043d\u044b\u0445. \u0410\u043d\u0430\u043b\u043e\u0433\u0438\u0447\u043d\u043e \u043f\u0440\u0438 \u043f\u043e\u043f\u044b\u0442\u043a\u0435 \u0437\u0430\u043f\u0438\u0441\u0438 \u0432 \u0437\u0430\u043f\u043e\u043b\u043d\u0435\u043d\u043d\u044b\u0439 \u0431\u0443\u0444\u0435\u0440 \u043f\u0440\u043e\u0446\u0435\u0441\u0441 \u0437\u0430\u043f\u0438\u0441\u0438 \u0431\u0443\u0434\u0435\u0442 \u0437\u0430\u0431\u043b\u043e\u043a\u0438\u0440\u043e\u0432\u0430\u043d \u0434\u043e \u043e\u0441\u0432\u043e\u0431\u043e\u0436\u0434\u0435\u043d\u0438\u044f \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0433\u043e \u043c\u0435\u0441\u0442\u0430.<br \/>  \u0412\u0430\u0436\u043d\u043e, \u0447\u0442\u043e \u043d\u0435\u0441\u043c\u043e\u0442\u0440\u044f \u043d\u0430 \u0442\u043e, \u0447\u0442\u043e \u043a\u043e\u043d\u0432\u0435\u0439\u0435\u0440 \u043e\u043f\u0435\u0440\u0438\u0440\u0443\u0435\u0442 \u0444\u0430\u0439\u043b\u043e\u0432\u044b\u043c\u0438 \u0434\u0435\u0441\u043a\u0440\u0438\u043f\u0442\u043e\u0440\u0430\u043c\u0438 \u043f\u043e\u0442\u043e\u043a\u043e\u0432 \u0432\u0432\u043e\u0434\u0430\/\u0432\u044b\u0432\u043e\u0434\u0430, \u0432\u0441\u0435 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0438 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u044e\u0442\u0441\u044f \u0432 \u043f\u0430\u043c\u044f\u0442\u0438, \u0431\u0435\u0437 \u043d\u0430\u0433\u0440\u0443\u0437\u043a\u0438 \u043d\u0430 \u0434\u0438\u0441\u043a.<br \/>  \u0412\u0441\u044f \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044f, \u043f\u0440\u0438\u0432\u0435\u0434\u0435\u043d\u043d\u0430\u044f \u043d\u0438\u0436\u0435, \u043a\u0430\u0441\u0430\u0435\u0442\u0441\u044f \u043e\u0431\u043e\u043b\u043e\u0447\u043a\u0438 bash-4.2 \u0438 \u044f\u0434\u0440\u0430 3.10.10.<\/p>\n<h4>\u041f\u0440\u043e\u0441\u0442\u043e\u0439 \u0434\u0435\u0431\u0430\u0433<\/h4>\n<p>  \u0423\u0442\u0438\u043b\u0438\u0442\u0430 strace \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u043e\u0442\u0441\u043b\u0435\u0434\u0438\u0442\u044c \u0441\u0438\u0441\u0442\u0435\u043c\u043d\u044b\u0435 \u0432\u044b\u0437\u043e\u0432\u044b \u0432 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0435 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u044b:  <\/p>\n<pre><code class=\"bash\">$ strace -f bash -c \u2018\/bin\/echo foo | grep bar\u2019 .... getpid() = 13726                   &lt;\u2013 PID \u043e\u0441\u043d\u043e\u0432\u043d\u043e\u0433\u043e \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0430 ... pipe([3,  4])                       &lt;\u2013 \u0441\u0438\u0441\u0442\u0435\u043c\u043d\u044b\u0439 \u0432\u044b\u0437\u043e\u0432 \u0434\u043b\u044f \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u043a\u043e\u043d\u0432\u0435\u0435\u0440\u0430 .... clone(....) = 13727                &lt;\u2013 \u043f\u043e\u0434\u043f\u0440\u043e\u0446\u0435\u0441\u0441 \u0434\u043b\u044f \u043f\u0435\u0440\u0432\u043e\u0439 \u043a\u043e\u043c\u0430\u043d\u0434\u044b \u043a\u043e\u043d\u0432\u0435\u0435\u0440\u0430 (echo) ... [pid 13727] execve(&quot;\/bin\/echo&quot;,  [&quot;\/bin\/echo&quot;,  &quot;foo&quot;],  [\/* 61 vars *\/]  ..... [pid 13726] clone(....) = 13728    &lt;\u2013 \u043f\u043e\u0434\u043f\u0440\u043e\u0446\u0435\u0441\u0441 \u0434\u043b\u044f \u0432\u0442\u043e\u0440\u043e\u0439 \u043a\u043e\u043c\u0430\u043d\u0434\u044b (grep) \u0441\u043e\u0437\u0434\u0430\u0435\u0442\u0441\u044f \u0442\u0430\u043a \u0436\u0435 \u043e\u0441\u043d\u043e\u0432\u043d\u044b\u043c \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u043e\u043c ... [pid 13728] stat(&quot;\/home\/aikikode\/bin\/grep&quot;,    ... <\/code><\/pre>\n<p>\u0412\u0438\u0434\u043d\u043e, \u0447\u0442\u043e \u0434\u043b\u044f \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u043a\u043e\u043d\u0432\u0435\u0435\u0440\u0430 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0441\u0438\u0441\u0442\u0435\u043c\u043d\u044b\u0439 \u0432\u044b\u0437\u043e\u0432 pipe(), \u0430 \u0442\u0430\u043a\u0436\u0435, \u0447\u0442\u043e \u043e\u0431\u0430 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0430 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u044e\u0442\u0441\u044f \u043f\u0430\u0440\u0430\u043b\u043b\u0435\u043b\u044c\u043d\u043e \u0432 \u0440\u0430\u0437\u043d\u044b\u0445 \u043f\u043e\u0442\u043e\u043a\u0430\u0445.<br \/>  <a name=\"habracut\"><\/a>  <\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">\u041c\u043d\u043e\u0433\u043e \u0438\u0441\u0445\u043e\u0434\u043d\u043e\u0433\u043e \u043a\u043e\u0434\u0430 bash \u0438 \u044f\u0434\u0440\u0430<\/b><\/p>\n<div class=\"spoiler_text\">\n<h4>\u0418\u0441\u0445\u043e\u0434\u043d\u044b\u0439 \u043a\u043e\u0434, \u0443\u0440\u043e\u0432\u0435\u043d\u044c 1, shell<\/h4>\n<p>  \u0422. \u043a. \u043b\u0443\u0447\u0448\u0430\u044f \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u044f \u2014 \u0438\u0441\u0445\u043e\u0434\u043d\u044b\u0439 \u043a\u043e\u0434, \u043e\u0431\u0440\u0430\u0442\u0438\u043c\u0441\u044f \u043a \u043d\u0435\u043c\u0443. Bash \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442 Yacc \u0434\u043b\u044f \u043f\u0430\u0440\u0441\u0438\u043d\u0433\u0430 \u0432\u0445\u043e\u0434\u043d\u044b\u0445 \u043a\u043e\u043c\u0430\u043d\u0434 \u0438 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u2018command_connect()\u2019, \u043a\u043e\u0433\u0434\u0430 \u0432\u0441\u0442\u0440\u0435\u0447\u0430\u0435\u0442 \u0441\u0438\u043c\u0432\u043e\u043b \u2018|\u2019.<br \/>  <a href=\"http:\/\/git.savannah.gnu.org\/cgit\/bash.git\/tree\/parse.y?id=bash-4.2#n1242\">parse.y<\/a>:  <\/p>\n<pre><code class=\"cpp\">1242 pipeline:   pipeline \u2018|\u2019 newline_list pipeline 1243             { $$ = command_connect ($1,  $4,  \u2018|\u2019); } 1244     |       pipeline BAR_AND newline_list pipeline 1245             { 1246               \/* Make cmd1 |& cmd2 equivalent to cmd1 2&gt;&1 | cmd2 *\/ 1247               COMMAND *tc; 1248               REDIRECTEE rd,  sd; 1249               REDIRECT *r; 1250  1251               tc = $1-&gt;type == cm_simple ? (COMMAND *)$1-&gt;value.Simple : $1; 1252               sd.dest = 2; 1253               rd.dest = 1; 1254               r = make_redirection (sd,  r_duplicating_output,  rd,  0); 1255               if (tc-&gt;redirects) 1256               { 1257                   register REDIRECT *t; 1258                   for (t = tc-&gt;redirects; t-&gt;next; t = t-&gt;next) 1259                       ; 1260                   t-&gt;next = r; 1261               } 1262               else 1263                   tc-&gt;redirects = r; 1264  1265               $$ = command_connect ($1,  $4,  \u2018|\u2019); 1266             } 1267     |       command 1268             { $$ = $1; } 1269     ; <\/code><\/pre>\n<p>\u0422\u0430\u043a\u0436\u0435 \u0437\u0434\u0435\u0441\u044c \u043c\u044b \u0432\u0438\u0434\u0438\u043c \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0443 \u043f\u0430\u0440\u044b \u0441\u0438\u043c\u0432\u043e\u043b\u043e\u0432 \u2018|&#038;\u2019, \u0447\u0442\u043e \u044d\u043a\u0432\u0438\u0432\u0430\u043b\u0435\u043d\u0442\u043d\u043e \u043f\u0435\u0440\u0435\u043d\u0430\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u044e \u043a\u0430\u043a stdout, \u0442\u0430\u043a \u0438 stderr \u0432 \u043a\u043e\u043d\u0432\u0435\u0435\u0440. \u0414\u0430\u043b\u0435\u0435 \u043e\u0431\u0440\u0430\u0442\u0438\u043c\u0441\u044f \u043a command_connect():<a href=\"http:\/\/git.savannah.gnu.org\/cgit\/bash.git\/tree\/make_cmd.c?id=bash-4.2#n194\">make_cmd.c<\/a>:  <\/p>\n<pre><code class=\"cpp\">194 COMMAND * 195 command_connect (com1,  com2,  connector) 196      COMMAND *com1,  *com2; 197      int connector; 198 { 199   CONNECTION *temp; 200  201   temp = (CONNECTION *)xmalloc (sizeof (CONNECTION)); 202   temp-&gt;connector = connector; 203   temp-&gt;first = com1; 204   temp-&gt;second = com2; 205   return (make_command (cm_connection,  (SIMPLE_COM *)temp)); 206 } <\/code><\/pre>\n<p>\u0433\u0434\u0435 connector \u044d\u0442\u043e \u0441\u0438\u043c\u0432\u043e\u043b \u2018|\u2019 \u043a\u0430\u043a int. \u041f\u0440\u0438 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0438 \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438 \u043a\u043e\u043c\u0430\u043d\u0434 (\u0441\u0432\u044f\u0437\u0430\u043d\u043d\u044b\u0445 \u0447\u0435\u0440\u0435\u0437 \u2018&#038;\u2019, \u2018|\u2019, \u2018;\u2019, \u0438 \u0442. \u0434.) \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f execute_connection():<a href=\"http:\/\/git.savannah.gnu.org\/cgit\/bash.git\/tree\/execute_cmd.c?id=bash-4.2#n2255\">execute_cmd.c<\/a>:  <\/p>\n<pre><code class=\"cpp\">2325     case \u2018|\u2019: ... 2331       exec_result = execute_pipeline (command,  asynchronous,  pipe_in,  pipe_out,  fds_to_close); <\/code><\/pre>\n<p>  PIPE_IN \u0438 PIPE_OUT \u2014 \u0444\u0430\u0439\u043b\u043e\u0432\u044b\u0435 \u0434\u0435\u0441\u043a\u0440\u0438\u043f\u0442\u043e\u0440\u044b, \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0449\u0438\u0435 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044e \u043e \u0432\u0445\u043e\u0434\u043d\u043e\u043c \u0438 \u0432\u044b\u0445\u043e\u0434\u043d\u043e\u043c \u043f\u043e\u0442\u043e\u043a\u0430\u0445. \u041e\u043d\u0438 \u043c\u043e\u0433\u0443\u0442 \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0442\u044c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 NO_PIPE, \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u043e\u0437\u043d\u0430\u0447\u0430\u0435\u0442, \u0447\u0442\u043e I\/O \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f stdin\/stdout.<br \/>  execute_pipeline() \u0434\u043e\u0432\u043e\u043b\u044c\u043d\u043e \u043e\u0431\u044a\u0435\u043c\u043d\u0430\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u044f, \u0438\u043c\u043f\u043b\u0435\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u044f \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442\u0441\u044f \u0432 <a href=\"http:\/\/git.savannah.gnu.org\/cgit\/bash.git\/tree\/execute_cmd.c?id=bash-4.2#n2094\">execute_cmd.c<\/a>. \u041c\u044b \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043d\u0430\u0438\u0431\u043e\u043b\u0435\u0435 \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u044b\u0435 \u0434\u043b\u044f \u043d\u0430\u0441 \u0447\u0430\u0441\u0442\u0438.<br \/>  <a href=\"http:\/\/git.savannah.gnu.org\/cgit\/bash.git\/tree\/execute_cmd.c?id=bash-4.2#n2112\">execute_cmd.c<\/a>:   <\/p>\n<pre><code class=\"cpp\">2112   prev = pipe_in; 2113   cmd = command; 2114 2115   while (cmd && cmd-&gt;type == cm_connection && 2116   cmd-&gt;value.Connection && cmd-&gt;value.Connection-&gt;connector == \u2018|\u2019) 2117     { 2118       \/* \u0421\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u043a\u043e\u043d\u0432\u0435\u0435\u0440\u0430 \u043c\u0435\u0436\u0434\u0443 \u0434\u0432\u0443\u043c\u044f \u043a\u043e\u043c\u0430\u043d\u0434\u0430\u043c\u0438 *\/ 2119       if (pipe (fildes) &lt; 0) 2120       { \/* \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u043c \u043e\u0448\u0438\u0431\u043a\u0443 *\/ } .......            \/* \u0412\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u043c \u043f\u0435\u0440\u0432\u0443\u044e \u043a\u043e\u043c\u0430\u043d\u0434\u0443 \u0438\u0437 \u043a\u043e\u043d\u0432\u0435\u0439\u0435\u0440\u0430,  \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435               \u0432\u0445\u043e\u0434\u043d\u044b\u0445 \u0434\u0430\u043d\u043d\u044b\u0445 prev \u2014 \u0432\u044b\u0432\u043e\u0434 \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0435\u0439 \u043a\u043e\u043c\u0430\u043d\u0434\u044b,  \u0430 \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435               \u0432\u044b\u0445\u043e\u0434\u043d\u044b\u0445 fildes[1] \u2014 \u0432\u044b\u0445\u043e\u0434\u043d\u043e\u0439 \u0444\u0430\u0439\u043b\u043e\u0432\u044b\u0439 \u0434\u0435\u0441\u043a\u0440\u0438\u043f\u0442\u043e\u0440,  \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u043d\u044b\u0439               \u0432 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0435 \u0432\u044b\u0437\u043e\u0432\u0430 pipe() *\/ 2178       execute_command_internal (cmd-&gt;value.Connection-&gt;first,  asynchronous,  2179         prev,  fildes[1],  fd_bitmap); 2180  2181       if (prev &gt;= 0) 2182           close (prev); 2183  2184       prev = fildes[0];    \/* \u041d\u0430\u0448 \u0432\u044b\u0432\u043e\u0434 \u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u0441\u044f \u0432\u0432\u043e\u0434\u043e\u043c \u0434\u043b\u044f \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0439 \u043a\u043e\u043c\u0430\u043d\u0434\u044b *\/ 2185       close (fildes[1]); ....... 2190       cmd = cmd-&gt;value.Connection-&gt;second;  \/* \u201c\u0421\u0434\u0432\u0438\u0433\u0430\u0435\u043c\u0441\u044f\u201d \u043d\u0430 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0443\u044e \u043a\u043e\u043c\u0430\u043d\u0434\u0443 \u0438\u0437 \u043a\u043e\u043d\u0432\u0435\u0439\u0435\u0440\u0430 *\/ 2191     } <\/code><\/pre>\n<p>\u0422\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c, bash \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0435\u0442 \u0441\u0438\u043c\u0432\u043e\u043b \u043a\u043e\u043d\u0432\u0435\u0439\u0435\u0440\u0430 \u043f\u0443\u0442\u0435\u043c \u0441\u0438\u0441\u0442\u0435\u043c\u043d\u043e\u0433\u043e \u0432\u044b\u0437\u043e\u0432\u0430 pipe() \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0432\u0441\u0442\u0440\u0435\u0442\u0438\u0432\u0448\u0435\u0433\u043e\u0441\u044f \u0441\u0438\u043c\u0432\u043e\u043b\u0430 \u2018|\u2019 \u0438 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u0442 \u043a\u0430\u0436\u0434\u0443\u044e \u043a\u043e\u043c\u0430\u043d\u0434\u0443 \u0432 \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u043e\u043c \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0435 \u0441 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0445 \u0444\u0430\u0439\u043b\u043e\u0432\u044b\u0445 \u0434\u0435\u0441\u043a\u0440\u0438\u043f\u0442\u043e\u0440\u043e\u0432 \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u0432\u0445\u043e\u0434\u043d\u043e\u0433\u043e \u0438 \u0432\u044b\u0445\u043e\u0434\u043d\u043e\u0433\u043e \u043f\u043e\u0442\u043e\u043a\u043e\u0432.<\/p>\n<h4>\u0418\u0441\u0445\u043e\u0434\u043d\u044b\u0439 \u043a\u043e\u0434, \u0443\u0440\u043e\u0432\u0435\u043d\u044c 2, \u044f\u0434\u0440\u043e<\/h4>\n<p>  \u041e\u0431\u0440\u0430\u0442\u0438\u043c\u0441\u044f \u043a \u043a\u043e\u0434\u0443 \u044f\u0434\u0440\u0430 \u0438 \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043d\u0430 \u0438\u043c\u043f\u043b\u0435\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u044e \u0444\u0443\u043d\u043a\u0446\u0438\u0438 pipe(). \u0412 \u0441\u0442\u0430\u0442\u044c\u0435 \u0440\u0430\u0441\u0441\u043c\u0430\u0442\u0440\u0438\u0432\u0430\u0435\u0442\u0441\u044f \u044f\u0434\u0440\u043e \u0432\u0435\u0440\u0441\u0438\u0438 3.10.10 stable.<br \/>  <a href=\"https:\/\/git.kernel.org\/cgit\/linux\/kernel\/git\/stable\/linux-stable.git\/tree\/fs\/pipe.c?id=refs\/tags\/v3.10.10\">fs\/pipe.c<\/a> (\u043f\u0440\u043e\u043f\u0443\u0449\u0435\u043d\u044b \u043d\u0435\u0437\u043d\u0430\u0447\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0435 \u0434\u043b\u044f \u0434\u0430\u043d\u043d\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0438 \u0443\u0447\u0430\u0441\u0442\u043a\u0438 \u043a\u043e\u0434\u0430):  <\/p>\n<pre><code class=\"cpp\">\/*     \u041c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u044b\u0439 \u0440\u0430\u0437\u043c\u0435\u0440 \u0431\u0443\u0444\u0435\u0440\u0430 \u043a\u043e\u043d\u0432\u0435\u0439\u0435\u0440\u0430 \u0434\u043b\u044f \u043d\u0435\u043f\u0440\u0438\u0432\u0438\u043b\u0435\u0433\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u043e\u0433\u043e \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f.     \u041c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u0432\u044b\u0441\u0442\u0430\u0432\u043b\u0435\u043d \u0440\u0443\u0442\u043e\u043c \u0432 \u0444\u0430\u0439\u043b\u0435 \/proc\/sys\/fs\/pipe-max-size   *\/   35 unsigned int pipe_max_size = 1048576;     \/*      \u041c\u0438\u043d\u0438\u043c\u0430\u043b\u044c\u043d\u044b\u0439 \u0440\u0430\u0437\u043c\u0435\u0440 \u0431\u0443\u0444\u0435\u0440\u0430 \u043a\u043e\u043d\u0432\u0435\u0435\u0440\u0430,  \u0441\u043e\u0433\u043b\u0430\u0441\u043d\u043e \u0440\u0435\u043a\u043e\u043c\u0435\u043d\u0434\u0430\u0446\u0438\u0438 POSIX      \u0440\u0430\u0432\u0435\u043d \u0440\u0430\u0437\u043c\u0435\u0440\u0443 \u043e\u0434\u043d\u043e\u0439 \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u044b \u043f\u0430\u043c\u044f\u0442\u0438,  \u0442.\u0435. 4\u041a\u0431     *\/   40 unsigned int pipe_min_size = PAGE_SIZE;   869 int create_pipe_files(struct file **res,  int flags)  870 {  871     int err;  872     struct inode *inode = get_pipe_inode();  873     struct file *f;  874     struct path path;  875     static struct qstr name = {. name = \u201c\u201d };          \/* \u0412\u044b\u0434\u0435\u043b\u044f\u0435\u043c dentry \u0432 dcache *\/  881     path.dentry = d_alloc_pseudo(pipe_mnt-&gt;mnt_sb,  &name);          \/* \u0412\u044b\u0434\u0435\u043b\u044f\u0435\u043c \u0438 \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0438\u0440\u0443\u0435\u043c \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0443 file. \u041e\u0431\u0440\u0430\u0442\u0438\u0442\u0435 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435             \u043d\u0430 FMODE_WRITE,  \u0430 \u0442\u0430\u043a\u0436\u0435 \u043d\u0430 \u0444\u043b\u0430\u0433 O_WRONLY,  \u0442.\u0435. \u044d\u0442\u0430 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0430             \u0442\u043e\u043b\u044c\u043a\u043e \u0434\u043b\u044f \u0437\u0430\u043f\u0438\u0441\u0438 \u0438 \u0431\u0443\u0434\u0435\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u043a\u0430\u043a \u0432\u044b\u0445\u043e\u0434\u043d\u043e\u0439 \u043f\u043e\u0442\u043e\u043a             \u0432 \u043a\u043e\u043d\u0432\u0435\u0435\u0440\u0435. \u041a \u0444\u043b\u0430\u0433\u0443 O_NONBLOCK \u043c\u044b \u0435\u0449\u0435 \u0432\u0435\u0440\u043d\u0435\u043c\u0441\u044f. *\/  889     f = alloc_file(&path,  FMODE_WRITE,  &pipefifo_fops);  893     f-&gt;f_flags = O_WRONLY | (flags & (O_NONBLOCK | O_DIRECT));          \/* \u0410\u043d\u0430\u043b\u043e\u0433\u0438\u0447\u043d\u043e \u0432\u044b\u0434\u0435\u043b\u044f\u0435\u043c \u0438 \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0438\u0440\u0443\u0435\u043c \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0443 file \u0434\u043b\u044f \u0447\u0442\u0435\u043d\u0438\u044f             (\u0441\u043c. FMODE_READ \u0438 \u0444\u043b\u0430\u0433 O_RDONLY) *\/  896     res[0] = alloc_file(&path,  FMODE_READ,  &pipefifo_fops);  902     res[0]-&gt;f_flags = O_RDONLY | (flags & O_NONBLOCK);  903     res[1] = f;  904     return 0;  917 }  918  919 static int __do_pipe_flags(int *fd,  struct file **files,  int flags)  920 {  921     int error;  922     int fdw,  fdr;          \/* \u0421\u043e\u0437\u0434\u0430\u0435\u043c \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u044b file \u0434\u043b\u044f \u0444\u0430\u0439\u043b\u043e\u0432\u044b\u0445 \u0434\u0435\u0441\u043a\u0440\u0438\u043f\u0442\u043e\u0440\u043e\u0432 \u043a\u043e\u043d\u0432\u0435\u0435\u0440\u0430             (\u0441\u043c. \u0444\u0443\u043d\u043a\u0446\u0438\u044e \u0432\u044b\u0448\u0435) *\/   927     error = create_pipe_files(files,  flags);          \/* \u0412\u044b\u0431\u0438\u0440\u0430\u0435\u043c \u0441\u0432\u043e\u0431\u043e\u0434\u043d\u044b\u0435 \u0444\u0430\u0439\u043b\u043e\u0432\u044b\u0435 \u0434\u0435\u0441\u043a\u0440\u0438\u043f\u0442\u043e\u0440\u044b *\/  931     fdr = get_unused_fd_flags(flags);  936     fdw = get_unused_fd_flags(flags);  941     audit_fd_pair(fdr,  fdw);  942     fd[0] = fdr;  943     fd[1] = fdw;  944     return 0;  952 }      \/* \u041d\u0435\u043f\u043e\u0441\u0440\u0435\u0434\u0441\u0442\u0432\u0435\u043d\u043d\u043e \u0438\u043c\u043f\u043b\u0435\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u0439         int pipe2(int pipefd[2],  int flags)... *\/  969 SYSCALL_DEFINE2(pipe2,  int __user *,  fildes,  int,  flags)  970 {  971     struct file *files[2];  972     int fd[2];          \/* \u0421\u043e\u0437\u0434\u0430\u0435\u043c \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u044b \u0434\u043b\u044f \u0432\u0432\u043e\u0434\u0430\/\u0432\u044b\u0432\u043e\u0434\u0430 \u0438 \u0438\u0449\u0435\u043c \u0441\u0432\u043e\u0431\u043e\u0434\u043d\u044b\u0435 \u0434\u0435\u0441\u043a\u0440\u0438\u043f\u0442\u043e\u0440\u044b *\/  975     __do_pipe_flags(fd,  files,  flags);          \/* \u041a\u043e\u043f\u0438\u0440\u0443\u0435\u043c \u0444\u0430\u0439\u043b\u043e\u0432\u044b\u0435 \u0434\u0435\u0441\u043a\u0440\u0438\u043f\u0442\u043e\u0440\u044b \u0438\u0437 kernel space \u0432 user space *\/  977     copy_to_user(fildes,  fd,  sizeof(fd));          \/* \u041d\u0430\u0437\u043d\u0430\u0447\u0430\u0435\u043c \u0444\u0430\u0439\u043b\u043e\u0432\u044b\u0435 \u0434\u0435\u0441\u043a\u0440\u0438\u043f\u0442\u043e\u0440\u044b \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044f\u043c \u043d\u0430 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u044b *\/  984     fd_install(fd[0],  files[0]);  985     fd_install(fd[1],  files[1]);  989 }      \/* ...\u0438 int pipe(int pipefd[2]),  \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u043f\u043e \u0441\u0443\u0442\u0438 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f         \u043e\u0431\u043e\u043b\u043e\u0447\u043a\u043e\u0439 \u0434\u043b\u044f \u0432\u044b\u0437\u043e\u0432\u0430 pipe2 \u0441 \u0434\u0435\u0444\u043e\u043b\u0442\u043d\u044b\u043c\u0438 \u0444\u043b\u0430\u0433\u0430\u043c\u0438; *\/  991 SYSCALL_DEFINE1(pipe,  int __user *,  fildes)  992 {  993     return sys_pipe2(fildes,  0);  994 } <\/code><\/pre>\n<p>\u0415\u0441\u043b\u0438 \u0432\u044b \u043e\u0431\u0440\u0430\u0442\u0438\u043b\u0438 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435, \u0432 \u043a\u043e\u0434\u0435 \u0438\u0434\u0435\u0442 \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0430 \u043d\u0430 \u0444\u043b\u0430\u0433 O_NONBLOCK. \u0415\u0433\u043e \u043c\u043e\u0436\u043d\u043e \u0432\u044b\u0441\u0442\u0430\u0432\u0438\u0442\u044c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u044e F_SETFL \u0432 fcntl. \u041e\u043d \u043e\u0442\u0432\u0435\u0447\u0430\u0435\u0442 \u0437\u0430 \u043f\u0435\u0440\u0435\u0445\u043e\u0434 \u0432 \u0440\u0435\u0436\u0438\u043c \u0431\u0435\u0437 \u0431\u043b\u043e\u043a\u0438\u0440\u043e\u0432\u043a\u0438 I\/O \u043f\u043e\u0442\u043e\u043a\u043e\u0432 \u0432 \u043a\u043e\u043d\u0432\u0435\u0435\u0440\u0435. \u0412 \u044d\u0442\u043e\u043c \u0440\u0435\u0436\u0438\u043c\u0435 \u0432\u043c\u0435\u0441\u0442\u043e \u0431\u043b\u043e\u043a\u0438\u0440\u043e\u0432\u043a\u0438 \u043f\u0440\u043e\u0446\u0435\u0441\u0441 \u0447\u0442\u0435\u043d\u0438\u044f\/\u0437\u0430\u043f\u0438\u0441\u0438 \u0432 \u043f\u043e\u0442\u043e\u043a \u0431\u0443\u0434\u0435\u0442 \u0437\u0430\u0432\u0435\u0440\u0448\u0430\u0442\u044c\u0441\u044f \u0441 errno \u043a\u043e\u0434\u043e\u043c EAGAIN.<\/p>\n<p>  \u041c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u044b\u0439 \u0440\u0430\u0437\u043c\u0435\u0440 \u0431\u043b\u043e\u043a\u0430 \u0434\u0430\u043d\u043d\u044b\u0445, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0431\u0443\u0434\u0435\u0442 \u0437\u0430\u043f\u0438\u0441\u0430\u043d \u0432 \u043a\u043e\u043d\u0432\u0435\u0439\u0435\u0440, \u0440\u0430\u0432\u0435\u043d \u043e\u0434\u043d\u043e\u0439 \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u0435 \u043f\u0430\u043c\u044f\u0442\u0438 (4\u041a\u0431) \u0434\u043b\u044f \u0430\u0440\u0445\u0438\u0442\u0435\u043a\u0442\u0443\u0440\u044b asm:<br \/>  <a href=\"https:\/\/git.kernel.org\/cgit\/linux\/kernel\/git\/stable\/linux-stable.git\/tree\/arch\/arm\/include\/asm\/limits.h?id=refs\/tags\/v3.10.10\">arch\/arm\/include\/asm\/limits.h<\/a>:  <\/p>\n<pre><code class=\"cpp\"> 8 #define PIPE_BUF    PAGE_SIZE <\/code><\/pre>\n<p>\u0414\u043b\u044f \u044f\u0434\u0435\u0440 &gt;= 2.6.35 \u043c\u043e\u0436\u043d\u043e \u0438\u0437\u043c\u0435\u043d\u0438\u0442\u044c \u0440\u0430\u0437\u043c\u0435\u0440 \u0431\u0443\u0444\u0435\u0440\u0430 \u043a\u043e\u043d\u0432\u0435\u0439\u0435\u0440\u0430:  <\/p>\n<pre><code class=\"bash\">fcntl(fd,  F_SETPIPE_SZ,  &lt;size&gt;) <\/code><\/pre>\n<p>\u041c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u043e \u0434\u043e\u043f\u0443\u0441\u0442\u0438\u043c\u044b\u0439 \u0440\u0430\u0437\u043c\u0435\u0440 \u0431\u0443\u0444\u0435\u0440\u0430, \u043a\u0430\u043a \u043c\u044b \u0432\u0438\u0434\u0435\u043b\u0438 \u0432\u044b\u0448\u0435, \u0443\u043a\u0430\u0437\u0430\u043d \u0432 \u0444\u0430\u0439\u043b\u0435 \/proc\/sys\/fs\/pipe-max-size.  <\/div>\n<\/div>\n<p>  <\/p>\n<h4>Tips &#038; trics<\/h4>\n<p>  \u0412 \u043f\u0440\u0438\u043c\u0435\u0440\u0430\u0445 \u043d\u0438\u0436\u0435 \u0431\u0443\u0434\u0435\u043c \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0442\u044c ls \u043d\u0430 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u044e\u0449\u0443\u044e \u0434\u0438\u0440\u0435\u043a\u0442\u043e\u0440\u0438\u044e Documents \u0438 \u0434\u0432\u0430 \u043d\u0435\u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0445 \u0444\u0430\u0439\u043b\u0430: .\/non-existent_file \u0438. \/other_non-existent_file.<\/p>\n<ol>\n<li>\n<h5>\u041f\u0435\u0440\u0435\u043d\u0430\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u0438 stdout, \u0438 stderr \u0432 pipe<\/h5>\n<p>  <\/p>\n<pre><code class=\"bash\">ls -d .\/Documents .\/non-existent_file .\/other_non-existent_file 2&gt;&1 | egrep \u201cDoc|other\u201d ls: cannot access .\/other_non-existent_file: No such file or directory .\/Documents <\/code><\/pre>\n<p>\u0438\u043b\u0438 \u0436\u0435 \u043c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043a\u043e\u043c\u0431\u0438\u043d\u0430\u0446\u0438\u044e \u0441\u0438\u043c\u0432\u043e\u043b\u043e\u0432 \u2018|$\u2019 (\u043e \u043d\u0435\u0439 \u043c\u043e\u0436\u043d\u043e \u0443\u0437\u043d\u0430\u0442\u044c \u043a\u0430\u043a \u0438\u0437 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u0438 \u043a \u043e\u0431\u043e\u043b\u043e\u0447\u043a\u0435 (man bash), \u0442\u0430\u043a \u0438 \u0438\u0437 \u0438\u0441\u0445\u043e\u0434\u043d\u0438\u043a\u043e\u0432 \u0432\u044b\u0448\u0435, \u0433\u0434\u0435 \u043c\u044b \u0440\u0430\u0437\u0431\u0438\u0440\u0430\u043b\u0438 Yacc \u043f\u0430\u0440\u0441\u0435\u0440 bash):  <\/p>\n<pre><code class=\"bash\">ls -d .\/Documents .\/non-existent_file .\/other_non-existent_file |& egrep \u201cDoc|other\u201d ls: cannot access .\/other_non-existent_file: No such file or directory .\/Documents <\/code><\/pre>\n<p>  <\/li>\n<li>\n<h5>\u041f\u0435\u0440\u0435\u043d\u0430\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u0435 _\u0442\u043e\u043b\u044c\u043a\u043e_ stderr \u0432 pipe<\/h5>\n<p>  <\/p>\n<pre><code class=\"bash\">$ ls -d .\/Documents .\/non-existent_file .\/other_non-existent_file 2&gt;&1 &gt;\/dev\/null | egrep \u201cDoc|other\u201d ls: cannot access .\/other_non-existent_file: No such file or directory <\/code><\/pre>\n<p><i><b>Shoot yourself in the foot<\/b><br \/>  \u0412\u0430\u0436\u043d\u043e \u0441\u043e\u0431\u043b\u044e\u0434\u0430\u0442\u044c \u043f\u043e\u0440\u044f\u0434\u043e\u043a \u043f\u0435\u0440\u0435\u043d\u0430\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u044f stdout \u0438 stderr. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043a\u043e\u043c\u0431\u0438\u043d\u0430\u0446\u0438\u044f \u2018&gt;\/dev\/null 2&gt;&#038;1\u2032 \u043f\u0435\u0440\u0435\u043d\u0430\u043f\u0440\u0430\u0432\u0438\u0442 \u0438 stdout, \u0438 stderr \u0432 \/dev\/null.<\/i><\/p>\n<\/li>\n<li>\n<h5>\u041f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u0435 \u043a\u043e\u0440\u0440\u0435\u043a\u0442\u043d\u043e\u0433\u043e \u043a\u043e\u0434\u0430 \u0437\u0430\u0432\u0435\u0440\u0448\u0435\u043d\u0438\u044f \u043a\u043e\u043d\u0432\u0435\u0439\u0440\u0430<\/h5>\n<p>  \u041f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e, \u043a\u043e\u0434 \u0437\u0430\u0432\u0435\u0440\u0448\u0435\u043d\u0438\u044f \u043a\u043e\u043d\u0432\u0435\u0439\u0435\u0440\u0430 \u2014 \u043a\u043e\u0434 \u0437\u0430\u0432\u0435\u0440\u0448\u0435\u043d\u0438\u044f \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0435\u0439 \u043a\u043e\u043c\u0430\u043d\u0434\u044b \u0432 \u043a\u043e\u043d\u0432\u0435\u0435\u0440\u0435. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0432\u043e\u0437\u044c\u043c\u0435\u043c \u0438\u0441\u0445\u043e\u0434\u043d\u0443\u044e \u043a\u043e\u043c\u0430\u043d\u0434\u0443, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0437\u0430\u0432\u0435\u0440\u0448\u0430\u0435\u0442\u0441\u044f \u0441 \u043d\u0435\u043d\u0443\u043b\u0435\u0432\u044b\u043c \u043a\u043e\u0434\u043e\u043c:  <\/p>\n<pre><code class=\"bash\">$ ls -d .\/non-existent_file 2&gt;\/dev\/null; echo $? 2 <\/code><\/pre>\n<p>\u0418 \u043f\u043e\u043c\u0435\u0441\u0442\u0438\u043c \u0435\u0435 \u0432 pipe:  <\/p>\n<pre><code class=\"bash\">$ ls -d .\/non-existent_file 2&gt;\/dev\/null | wc; echo $?       0       0       0 0 <\/code><\/pre>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u043a\u043e\u0434 \u0437\u0430\u0432\u0435\u0440\u0448\u0435\u043d\u0438\u044f \u043a\u043e\u043d\u0432\u0435\u0439\u0435\u0440\u0430 \u2014 \u044d\u0442\u043e \u043a\u043e\u0434 \u0437\u0430\u0432\u0435\u0440\u0448\u0435\u043d\u0438\u044f \u043a\u043e\u043c\u0430\u043d\u0434\u044b wc, \u0442.\u0435. 0.<\/p>\n<p>  \u041e\u0431\u044b\u0447\u043d\u043e \u0436\u0435 \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u0437\u043d\u0430\u0442\u044c, \u0435\u0441\u043b\u0438 \u0432 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0435 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u043a\u043e\u043d\u0432\u0435\u0439\u0435\u0440\u0430 \u043f\u0440\u043e\u0438\u0437\u043e\u0448\u043b\u0430 \u043e\u0448\u0438\u0431\u043a\u0430. \u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u0441\u043b\u0435\u0434\u0443\u0435\u0442 \u0432\u044b\u0441\u0442\u0430\u0432\u0438\u0442\u044c \u043e\u043f\u0446\u0438\u044e pipefail, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442 \u043e\u0431\u043e\u043b\u043e\u0447\u043a\u0435, \u0447\u0442\u043e \u043a\u043e\u0434 \u0437\u0430\u0432\u0435\u0440\u0448\u0435\u043d\u0438\u044f \u043a\u043e\u043d\u0432\u0435\u0439\u0435\u0440\u0430 \u0431\u0443\u0434\u0435\u0442 \u0441\u043e\u0432\u043f\u0430\u0434\u0430\u0442\u044c \u0441 \u043f\u0435\u0440\u0432\u044b\u043c \u043d\u0435\u043d\u0443\u043b\u0435\u0432\u044b\u043c \u043a\u043e\u0434\u043e\u043c \u0437\u0430\u0432\u0435\u0440\u0448\u0435\u043d\u0438\u044f \u043e\u0434\u043d\u043e\u0439 \u0438\u0437 \u043a\u043e\u043c\u0430\u043d\u0434 \u043a\u043e\u043d\u0432\u0435\u0439\u0435\u0440\u0430 \u0438\u043b\u0438 \u0436\u0435 \u043d\u0443\u043b\u044e \u0432 \u0441\u043b\u0443\u0447\u0430\u0435, \u0435\u0441\u043b\u0438 \u0432\u0441\u0435 \u043a\u043e\u043c\u0430\u043d\u0434\u044b \u0437\u0430\u0432\u0435\u0440\u0448\u0438\u043b\u0438\u0441\u044c \u043a\u043e\u0440\u0440\u0435\u043a\u0442\u043d\u043e:  <\/p>\n<pre><code class=\"bash\">$ set -o pipefail $ ls -d .\/non-existent_file 2&gt;\/dev\/null | wc; echo $?       0       0       0 2 <\/code><\/pre>\n<p><i><b>Shoot yourself in the foot<\/b><br \/>  \u0421\u043b\u0435\u0434\u0443\u0435\u0442 \u0438\u043c\u0435\u0442\u044c \u0432 \u0432\u0438\u0434\u0443 \u201c\u0431\u0435\u0437\u043e\u0431\u0438\u0434\u043d\u044b\u0435\u201d \u043a\u043e\u043c\u0430\u043d\u0434\u044b, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043c\u043e\u0433\u0443\u0442 \u0432\u0435\u0440\u043d\u0443\u0442\u044c \u043d\u0435 \u043d\u043e\u043b\u044c. \u042d\u0442\u043e \u043a\u0430\u0441\u0430\u0435\u0442\u0441\u044f \u043d\u0435 \u0442\u043e\u043b\u044c\u043a\u043e \u0440\u0430\u0431\u043e\u0442\u044b \u0441 \u043a\u043e\u043d\u0432\u0435\u0439\u0435\u0440\u0430\u043c\u0438. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043f\u0440\u0438\u043c\u0435\u0440 \u0441 grep:  <\/p>\n<pre><code class=\"bash\">$ egrep \u201c^foo=[0-9]+\u201d .\/config | awk \u2018{print \u201cnew_\u201d$0;}\u2019 <\/code><\/pre>\n<p>\u0417\u0434\u0435\u0441\u044c \u043c\u044b \u043f\u0435\u0447\u0430\u0442\u0430\u0435\u043c \u0432\u0441\u0435 \u043d\u0430\u0439\u0434\u0435\u043d\u043d\u044b\u0435 \u0441\u0442\u0440\u043e\u043a\u0438, \u043f\u0440\u0438\u043f\u0438\u0441\u0430\u0432 \u2018new_\u2019 \u0432 \u043d\u0430\u0447\u0430\u043b\u0435 \u043a\u0430\u0436\u0434\u043e\u0439 \u0441\u0442\u0440\u043e\u043a\u0438, \u043b\u0438\u0431\u043e \u043d\u0435 \u043f\u0435\u0447\u0430\u0442\u0430\u0435\u043c \u043d\u0438\u0447\u0435\u0433\u043e, \u0435\u0441\u043b\u0438 \u043d\u0438 \u043e\u0434\u043d\u043e\u0439 \u0441\u0442\u0440\u043e\u043a\u0438 \u043d\u0443\u0436\u043d\u043e\u0433\u043e \u0444\u043e\u0440\u043c\u0430\u0442\u0430 \u043d\u0435 \u043d\u0430\u0448\u043b\u043e\u0441\u044c. \u041f\u0440\u043e\u0431\u043b\u0435\u043c\u0430 \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e grep \u0437\u0430\u0432\u0435\u0440\u0448\u0430\u0435\u0442\u0441\u044f \u0441 \u043a\u043e\u0434\u043e\u043c 1, \u0435\u0441\u043b\u0438 \u043d\u0435 \u0431\u044b\u043b\u043e \u043d\u0430\u0439\u0434\u0435\u043d\u043e \u043d\u0438 \u043e\u0434\u043d\u043e\u0433\u043e \u0441\u043e\u0432\u043f\u0430\u0434\u0435\u043d\u0438\u044f, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0435\u0441\u043b\u0438 \u0432 \u043d\u0430\u0448\u0435\u043c \u0441\u043a\u0440\u0438\u043f\u0442\u0435 \u0432\u044b\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0430 \u043e\u043f\u0446\u0438\u044f pipefail, \u044d\u0442\u043e\u0442 \u043f\u0440\u0438\u043c\u0435\u0440 \u0437\u0430\u0432\u0435\u0440\u0448\u0438\u0442\u0441\u044f \u0441 \u043a\u043e\u0434\u043e\u043c 1:  <\/p>\n<pre><code class=\"bash\">$ set -o pipefail $ egrep \u201c^foo=[0-9]+\u201d .\/config | awk \u2018{print \u201cnew_\u201d$0;}\u2019 &gt;\/dev\/null; echo $? 1 <\/code><\/pre>\n<p>\u0412 \u0431\u043e\u043b\u044c\u0448\u0438\u0445 \u0441\u043a\u0440\u0438\u043f\u0442\u0430\u0445 \u0441\u043e \u0441\u043b\u043e\u0436\u043d\u044b\u043c\u0438 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u044f\u043c\u0438 \u0438 \u0434\u043b\u0438\u043d\u043d\u044b\u043c\u0438 \u043a\u043e\u043d\u0432\u0435\u0435\u0440\u0430\u043c\u0438 \u043c\u043e\u0436\u043d\u043e \u0443\u043f\u0443\u0441\u0442\u0438\u0442\u044c \u044d\u0442\u043e\u0442 \u043c\u043e\u043c\u0435\u043d\u0442 \u0438\u0437 \u0432\u0438\u0434\u0443, \u0447\u0442\u043e \u043c\u043e\u0436\u0435\u0442 \u043f\u0440\u0438\u0432\u0435\u0441\u0442\u0438 \u043a \u043d\u0435\u043a\u043e\u0440\u0440\u0435\u043a\u0442\u043d\u044b\u043c \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0430\u043c.<\/i><\/p>\n<\/li>\n<li>\n<h5>\u041f\u0440\u0438\u0441\u0432\u043e\u0435\u043d\u0438\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u043c \u0432 \u043a\u043e\u043d\u0432\u0435\u0439\u0435\u0440\u0435<\/h5>\n<p>  \u0414\u043b\u044f \u043d\u0430\u0447\u0430\u043b\u0430 \u0432\u0441\u043f\u043e\u043c\u043d\u0438\u043c, \u0447\u0442\u043e \u0432\u0441\u0435 \u043a\u043e\u043c\u0430\u043d\u0434\u044b \u0432 \u043a\u043e\u043d\u0432\u0435\u0439\u0435\u0440\u0435 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u044e\u0442\u0441\u044f \u0432 \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u044b\u0445 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0430\u0445, \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u043d\u044b\u0445 \u0432\u044b\u0437\u043e\u0432\u043e\u043c clone(). \u041a\u0430\u043a \u043f\u0440\u0430\u0432\u0438\u043b\u043e, \u044d\u0442\u043e \u043d\u0435 \u0441\u043e\u0437\u0434\u0430\u0435\u0442 \u043f\u0440\u043e\u0431\u043b\u0435\u043c, \u0437\u0430 \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435\u043c \u0441\u043b\u0443\u0447\u0430\u0435\u0432 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u044f \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0445.<br \/>  \u0420\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 \u043f\u0440\u0438\u043c\u0435\u0440:  <\/p>\n<pre><code class=\"bash\">$ a=aaa $ b=bbb $ echo \u201cone two\u201d | read a b <\/code><\/pre>\n<p>\u041c\u044b \u043e\u0436\u0438\u0434\u0430\u0435\u043c, \u0447\u0442\u043e \u0442\u0435\u043f\u0435\u0440\u044c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0445 a \u0438 b \u0431\u0443\u0434\u0443\u0442 \u201cone\u201d \u0438 \u201ctwo\u201d \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0435\u043d\u043d\u043e. \u041d\u0430 \u0441\u0430\u043c\u043e\u043c \u0434\u0435\u043b\u0435 \u043e\u043d\u0438 \u043e\u0441\u0442\u0430\u043d\u0443\u0442\u0441\u044f \u201caaa\u201d \u0438 \u201cbbb\u201d. \u0412\u043e\u043e\u0431\u0449\u0435 \u043b\u044e\u0431\u043e\u0435 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0445 \u0432 \u043a\u043e\u043d\u0432\u0435\u0439\u0435\u0440\u0435 \u0437\u0430 \u0435\u0433\u043e \u043f\u0440\u0435\u0434\u0435\u043b\u0430\u043c\u0438 \u043e\u0441\u0442\u0430\u0432\u0438\u0442 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0435 \u0431\u0435\u0437 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u0439:  <\/p>\n<pre><code class=\"bash\">$ filefound=0 $ find . -type f -size +100k |     while true     do         read f         echo \u201c$f is over 100KB\u201d         filefound=1         break          # \u0432\u044b\u0445\u043e\u0434\u0438\u043c \u043f\u043e\u0441\u043b\u0435 \u043f\u0435\u0440\u0432\u043e\u0433\u043e \u043d\u0430\u0439\u0434\u0435\u043d\u043d\u043e\u0433\u043e \u0444\u0430\u0439\u043b\u0430     done $ echo $filefound; <\/code><\/pre>\n<p>\u0414\u0430\u0436\u0435 \u0435\u0441\u043b\u0438 find \u043d\u0430\u0439\u0434\u0435\u0442 \u0444\u0430\u0439\u043b \u0431\u043e\u043b\u044c\u0448\u0435 100\u041a\u0431, \u0444\u043b\u0430\u0433 filefound \u0432\u0441\u0435 \u0440\u0430\u0432\u043d\u043e \u0431\u0443\u0434\u0435\u0442 \u0438\u043c\u0435\u0442\u044c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 0.<br \/>  \u0412\u043e\u0437\u043c\u043e\u0436\u043d\u044b \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0440\u0435\u0448\u0435\u043d\u0438\u0439 \u044d\u0442\u043e\u0439 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u044b:  <\/p>\n<ul>\n<li>\u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\n<pre><code class=\"bash\">set -- $var <\/code><\/pre>\n<p>  \u0414\u0430\u043d\u043d\u0430\u044f \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u044f \u0432\u044b\u0441\u0442\u0430\u0432\u0438\u0442 \u043f\u043e\u0437\u0438\u0446\u0438\u043e\u043d\u043d\u044b\u0435 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0435 \u0441\u043e\u0433\u043b\u0430\u0441\u043d\u043e \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u043c\u043e\u043c\u0443 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0439 var. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043a\u0430\u043a \u0432 \u043f\u0435\u0440\u0432\u043e\u043c \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u0432\u044b\u0448\u0435:  <\/p>\n<pre><code class=\"bash\">$ var=\u201done two\u201d $ set -- $var $ a=$1   # \u201cone\u201d $ b=$2   # \u201ctwo\u201d <\/code><\/pre>\n<p>\u041d\u0443\u0436\u043d\u043e \u0438\u043c\u0435\u0442\u044c \u0432 \u0432\u0438\u0434\u0443, \u0447\u0442\u043e \u0432 \u0441\u043a\u0440\u0438\u043f\u0442\u0435 \u043f\u0440\u0438 \u044d\u0442\u043e\u043c \u0431\u0443\u0434\u0443\u0442 \u0443\u0442\u0435\u0440\u044f\u043d\u044b \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b\u044c\u043d\u044b\u0435 \u043f\u043e\u0437\u0438\u0446\u0438\u043e\u043d\u043d\u044b\u0435 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b, \u0441 \u043a\u043e\u0442\u043e\u0440\u044b\u043c\u0438 \u043e\u043d \u0431\u044b\u043b \u0432\u044b\u0437\u0432\u0430\u043d.<\/li>\n<li>\u043f\u0435\u0440\u0435\u043d\u0435\u0441\u0442\u0438 \u0432\u0441\u044e \u043b\u043e\u0433\u0438\u043a\u0443 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0439 \u0432 \u0442\u043e\u0442 \u0436\u0435 \u043f\u043e\u0434\u043f\u0440\u043e\u0446\u0435\u0441\u0441 \u0432 \u043a\u043e\u043d\u0432\u0435\u0439\u0435\u0440\u0435:<br \/> \n<pre><code class=\"bash\">$ echo \u201cone\u201d | (read a; echo $a;) one  <\/code><\/pre>\n<\/li>\n<li>\u0438\u0437\u043c\u0435\u043d\u0438\u0442\u044c \u043b\u043e\u0433\u0438\u043a\u0443, \u0447\u0442\u043e\u0431\u044b \u0438\u0437\u0431\u0435\u0436\u0430\u0442\u044c \u043f\u0440\u0438\u0441\u0432\u0430\u0438\u0432\u0430\u043d\u0438\u044f \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0445 \u0432\u043d\u0443\u0442\u0440\u0438 \u043a\u043e\u043d\u0432\u0435\u0435\u0440\u0430.<br \/>  \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0438\u0437\u043c\u0435\u043d\u0438\u043c \u043d\u0430\u0448 \u043f\u0440\u0438\u043c\u0435\u0440 \u0441 find:<br \/> \n<pre><code class=\"bash\">$ filefound=0 $ for f in $(find . -type f -size +100k)  # \u043c\u044b \u0443\u0431\u0440\u0430\u043b\u0438 \u043a\u043e\u043d\u0432\u0435\u0439\u0435\u0440,  \u0437\u0430\u043c\u0435\u043d\u0438\u0432 \u0435\u0433\u043e \u043d\u0430 \u0446\u0438\u043a\u043b     do         read f         echo \u201c$f is over 100KB\u201d         filefound=1         break     done $ echo $filefound; <\/code><\/pre>\n<\/li>\n<li>(\u0442\u043e\u043b\u044c\u043a\u043e \u0434\u043b\u044f bash-4.2 \u0438 \u043d\u043e\u0432\u0435\u0435) \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043e\u043f\u0446\u0438\u044e lastpipe<br \/>  \u041e\u043f\u0446\u0438\u044f lastpipe \u0434\u0430\u0435\u0442 \u0443\u043a\u0430\u0437\u0430\u043d\u0438\u0435 \u043e\u0431\u043e\u043b\u043e\u0447\u043a\u0435 \u0432\u044b\u043f\u043e\u043b\u043d\u0438\u0442\u044c \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u044e\u044e \u043a\u043e\u043c\u0430\u043d\u0434\u0443 \u043a\u043e\u043d\u0432\u0435\u0439\u0435\u0440\u0430 \u0432 \u043e\u0441\u043d\u043e\u0432\u043d\u043e\u043c \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0435.<br \/> \n<pre><code class=\"bash\">$ (shopt -s lastpipe; a=\u201daaa\u201d; echo \u201cone\u201d | read a; echo $a) one <\/code><\/pre>\n<p>\u0412\u0430\u0436\u043d\u043e, \u0447\u0442\u043e \u0432 \u043a\u043e\u043c\u0430\u043d\u0434\u043d\u043e\u0439 \u0441\u0442\u0440\u043e\u043a\u0435 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0432\u044b\u0441\u0442\u0430\u0432\u0438\u0442\u044c \u043e\u043f\u0446\u0438\u044e lastpipe \u0432 \u0442\u043e\u043c \u0436\u0435 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0435, \u0433\u0434\u0435 \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u0437\u044b\u0432\u0430\u0442\u044c\u0441\u044f \u0438 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0439 \u043a\u043e\u043d\u0432\u0435\u0439\u0435\u0440, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0441\u043a\u043e\u0431\u043a\u0438 \u0432 \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u0432\u044b\u0448\u0435 \u043e\u0431\u044f\u0437\u0430\u0442\u0435\u043b\u044c\u043d\u044b. \u0412 \u0441\u043a\u0440\u0438\u043f\u0442\u0430\u0445 \u0441\u043a\u043e\u0431\u043a\u0438 \u043d\u0435 \u043e\u0431\u044f\u0437\u0430\u0442\u0435\u043b\u044c\u043d\u044b.<\/li>\n<\/ul>\n<\/li>\n<\/ol>\n<p>  <\/p>\n<h4>\u0414\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u0430\u044f \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044f<\/h4>\n<p>  <\/p>\n<ul>\n<li>\u043f\u043e\u0434\u0440\u043e\u0431\u043d\u043e\u0435 \u043e\u043f\u0438\u0441\u0430\u043d\u0438\u0435 \u0441\u0438\u043d\u0442\u0430\u043a\u0441\u0438\u0441\u0430 \u043a\u043e\u043d\u0432\u0435\u0435\u0440\u0430: <a href=\"http:\/\/linux.die.net\/man\/1\/bash\">linux.die.net\/man\/1\/bash<\/a> (\u0441\u0435\u043a\u0446\u0438\u044f Pipelines), \u0438\u043b\u0438 \u2018man bash\u2019 \u0432 \u0442\u0435\u0440\u043c\u0438\u043d\u0430\u043b\u0435.<\/li>\n<li>\u043b\u043e\u0433\u0438\u043a\u0430 \u0440\u0430\u0431\u043e\u0442\u044b \u043a\u043e\u043d\u0432\u0435\u0435\u0440\u0430: <a href=\"http:\/\/linux.die.net\/man\/7\/pipe\">linux.die.net\/man\/7\/pipe<\/a> \u0438\u043b\u0438 \u2018man 7 pipe\u2019<\/li>\n<li>\u0438\u0441\u0445\u043e\u0434\u043d\u044b\u0439 \u043a\u043e\u0434 \u043e\u0431\u043e\u043b\u043e\u0447\u043a\u0438 bash: <a href=\"http:\/\/ftp.gnu.org\/gnu\/bash\/\">ftp.gnu.org\/gnu\/bash\/<\/a>, \u0440\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u0439: <a href=\"http:\/\/git.savannah.gnu.org\/cgit\/bash.git\">git.savannah.gnu.org\/cgit\/bash.git<\/a><\/li>\n<li>\u044f\u0434\u0440\u043e Linux: <a href=\"https:\/\/www.kernel.org\/\">www.kernel.org\/<\/a><\/li>\n<\/ul>\n<div class=\"clear\"><\/div>\n<\/p><\/div>\n<p> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"http:\/\/habrahabr.ru\/post\/195152\/\"> http:\/\/habrahabr.ru\/post\/195152\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<div class=\"content html_format\">\n<h4>Pipe \u2014 \u0447\u0442\u043e \u044d\u0442\u043e?<\/h4>\n<p>  Pipe (\u043a\u043e\u043d\u0432\u0435\u0435\u0440) \u2013 \u044d\u0442\u043e \u043e\u0434\u043d\u043e\u043d\u0430\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u043d\u044b\u0439 \u043a\u0430\u043d\u0430\u043b \u043c\u0435\u0436\u043f\u0440\u043e\u0446\u0435\u0441\u0441\u043e\u0440\u043d\u043e\u0433\u043e \u0432\u0437\u0430\u0438\u043c\u043e\u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044f. \u0422\u0435\u0440\u043c\u0438\u043d \u0431\u044b\u043b \u043f\u0440\u0438\u0434\u0443\u043c\u0430\u043d <a href=\"http:\/\/ru.wikipedia.org\/wiki\/%D0%9C%D0%B0%D0%BA%D0%B8%D0%BB%D1%80%D0%BE%D0%B9,_%D0%94%D1%83%D0%B3%D0%BB%D0%B0%D1%81\">\u0414\u0443\u0433\u043b\u0430\u0441\u043e\u043c \u041c\u0430\u043a\u0438\u043b\u0440\u043e\u0435\u043c<\/a> \u0434\u043b\u044f \u043a\u043e\u043c\u0430\u043d\u0434\u043d\u043e\u0439 \u043e\u0431\u043e\u043b\u043e\u0447\u043a\u0438 Unix \u0438 \u043d\u0430\u0437\u0432\u0430\u043d \u043f\u043e \u0430\u043d\u0430\u043b\u043e\u0433\u0438\u0438 \u0441 \u0442\u0440\u0443\u0431\u043e\u043f\u0440\u043e\u0432\u043e\u0434\u043e\u043c. \u041a\u043e\u043d\u0432\u0435\u0439\u0435\u0440\u044b \u0447\u0430\u0449\u0435 \u0432\u0441\u0435\u0433\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0442\u0441\u044f \u0432 shell-\u0441\u043a\u0440\u0438\u043f\u0442\u0430\u0445 \u0434\u043b\u044f \u0441\u0432\u044f\u0437\u0438 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u0438\u0445 \u043a\u043e\u043c\u0430\u043d\u0434 \u043f\u0443\u0442\u0435\u043c \u043f\u0435\u0440\u0435\u043d\u0430\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u0432\u044b\u0432\u043e\u0434\u0430 \u043e\u0434\u043d\u043e\u0439 \u043a\u043e\u043c\u0430\u043d\u0434\u044b (stdout) \u043d\u0430 \u0432\u0445\u043e\u0434 (stdin) \u043f\u043e\u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0439, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f \u0441\u0438\u043c\u0432\u043e\u043b \u043a\u043e\u043d\u0432\u0435\u0435\u0440\u0430 \u2018|\u2019:  <\/p>\n<pre><code class=\"bash\">cmd1 | cmd2 | .... | cmdN <\/code><\/pre>\n<p>  \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440:  <\/p>\n<pre><code class=\"bash\">$ grep -i \u201cerror\u201d .\/log | wc -l 43 <\/code><\/pre>\n<p>  grep \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u0442 \u0440\u0435\u0433\u0438\u0441\u0442\u0440\u043e\u043d\u0435\u0437\u0430\u0432\u0438\u0441\u0438\u043c\u044b\u0439 \u043f\u043e\u0438\u0441\u043a \u0441\u0442\u0440\u043e\u043a\u0438 \u201cerror\u201d \u0432 \u0444\u0430\u0439\u043b\u0435 log, \u043d\u043e \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u043f\u043e\u0438\u0441\u043a\u0430 \u043d\u0435 \u0432\u044b\u0432\u043e\u0434\u0438\u0442\u0441\u044f \u043d\u0430 \u044d\u043a\u0440\u0430\u043d, \u0430 \u043f\u0435\u0440\u0435\u043d\u0430\u043f\u0440\u0430\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043d\u0430 \u0432\u0445\u043e\u0434 (stdin) \u043a\u043e\u043c\u0430\u043d\u0434\u044b wc, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0432 \u0441\u0432\u043e\u044e \u043e\u0447\u0435\u0440\u0435\u0434\u044c \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u0442 \u043f\u043e\u0434\u0441\u0447\u0435\u0442 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u0430 \u0441\u0442\u0440\u043e\u043a.<\/p>\n<h4>\u041b\u043e\u0433\u0438\u043a\u0430<\/h4>\n<p>  \u041a\u043e\u043d\u0432\u0435\u0435\u0440 \u043e\u0431\u0435\u0441\u043f\u0435\u0447\u0438\u0432\u0430\u0435\u0442 \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u043e\u0435 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0435 \u043a\u043e\u043c\u0430\u043d\u0434 \u0441 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c \u0431\u0443\u0444\u0435\u0440\u0438\u0437\u0430\u0446\u0438\u0438 \u0432\u0432\u043e\u0434\u0430\/\u0432\u044b\u0432\u043e\u0434\u0430. \u0422\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c \u0432\u0441\u0435 \u043a\u043e\u043c\u0430\u043d\u0434\u044b \u0432 \u043a\u043e\u043d\u0432\u0435\u0439\u0435\u0440\u0435 \u0440\u0430\u0431\u043e\u0442\u0430\u044e\u0442 \u043f\u0430\u0440\u0430\u043b\u043b\u0435\u043b\u044c\u043d\u043e, \u043a\u0430\u0436\u0434\u0430\u044f \u0432 \u0441\u0432\u043e\u0435\u043c \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0435.<\/p>\n<p>  \u0420\u0430\u0437\u043c\u0435\u0440 \u0431\u0443\u0444\u0435\u0440\u0430 \u043d\u0430\u0447\u0438\u043d\u0430\u044f \u0441 \u044f\u0434\u0440\u0430 \u0432\u0435\u0440\u0441\u0438\u0438 2.6.11 \u0441\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 65536 \u0431\u0430\u0439\u0442 (64\u041a\u0431) \u0438 \u0440\u0430\u0432\u0435\u043d \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u0435 \u043f\u0430\u043c\u044f\u0442\u0438 \u0432 \u0431\u043e\u043b\u0435\u0435 \u0441\u0442\u0430\u0440\u044b\u0445 \u044f\u0434\u0440\u0430\u0445. \u041f\u0440\u0438 \u043f\u043e\u043f\u044b\u0442\u043a\u0435 \u0447\u0442\u0435\u043d\u0438\u044f \u0438\u0437 \u043f\u0443\u0441\u0442\u043e\u0433\u043e \u0431\u0443\u0444\u0435\u0440\u0430 \u043f\u0440\u043e\u0446\u0435\u0441\u0441 \u0447\u0442\u0435\u043d\u0438\u044f \u0431\u043b\u043e\u043a\u0438\u0440\u0443\u0435\u0442\u0441\u044f \u0434\u043e \u043f\u043e\u044f\u0432\u043b\u0435\u043d\u0438\u044f \u0434\u0430\u043d\u043d\u044b\u0445. \u0410\u043d\u0430\u043b\u043e\u0433\u0438\u0447\u043d\u043e \u043f\u0440\u0438 \u043f\u043e\u043f\u044b\u0442\u043a\u0435 \u0437\u0430\u043f\u0438\u0441\u0438 \u0432 \u0437\u0430\u043f\u043e\u043b\u043d\u0435\u043d\u043d\u044b\u0439 \u0431\u0443\u0444\u0435\u0440 \u043f\u0440\u043e\u0446\u0435\u0441\u0441 \u0437\u0430\u043f\u0438\u0441\u0438 \u0431\u0443\u0434\u0435\u0442 \u0437\u0430\u0431\u043b\u043e\u043a\u0438\u0440\u043e\u0432\u0430\u043d \u0434\u043e \u043e\u0441\u0432\u043e\u0431\u043e\u0436\u0434\u0435\u043d\u0438\u044f \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0433\u043e \u043c\u0435\u0441\u0442\u0430.<br \/>  \u0412\u0430\u0436\u043d\u043e, \u0447\u0442\u043e \u043d\u0435\u0441\u043c\u043e\u0442\u0440\u044f \u043d\u0430 \u0442\u043e, \u0447\u0442\u043e \u043a\u043e\u043d\u0432\u0435\u0439\u0435\u0440 \u043e\u043f\u0435\u0440\u0438\u0440\u0443\u0435\u0442 \u0444\u0430\u0439\u043b\u043e\u0432\u044b\u043c\u0438 \u0434\u0435\u0441\u043a\u0440\u0438\u043f\u0442\u043e\u0440\u0430\u043c\u0438 \u043f\u043e\u0442\u043e\u043a\u043e\u0432 \u0432\u0432\u043e\u0434\u0430\/\u0432\u044b\u0432\u043e\u0434\u0430, \u0432\u0441\u0435 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0438 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u044e\u0442\u0441\u044f \u0432 \u043f\u0430\u043c\u044f\u0442\u0438, \u0431\u0435\u0437 \u043d\u0430\u0433\u0440\u0443\u0437\u043a\u0438 \u043d\u0430 \u0434\u0438\u0441\u043a.<br \/>  \u0412\u0441\u044f \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044f, \u043f\u0440\u0438\u0432\u0435\u0434\u0435\u043d\u043d\u0430\u044f \u043d\u0438\u0436\u0435, \u043a\u0430\u0441\u0430\u0435\u0442\u0441\u044f \u043e\u0431\u043e\u043b\u043e\u0447\u043a\u0438 bash-4.2 \u0438 \u044f\u0434\u0440\u0430 3.10.10.<\/p>\n<h4>\u041f\u0440\u043e\u0441\u0442\u043e\u0439 \u0434\u0435\u0431\u0430\u0433<\/h4>\n<p>  \u0423\u0442\u0438\u043b\u0438\u0442\u0430 strace \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u043e\u0442\u0441\u043b\u0435\u0434\u0438\u0442\u044c \u0441\u0438\u0441\u0442\u0435\u043c\u043d\u044b\u0435 \u0432\u044b\u0437\u043e\u0432\u044b \u0432 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0435 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u044b:  <\/p>\n<pre><code class=\"bash\">$ strace -f bash -c \u2018\/bin\/echo foo | grep bar\u2019 .... getpid() = 13726                   &lt;\u2013 PID \u043e\u0441\u043d\u043e\u0432\u043d\u043e\u0433\u043e \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0430 ... pipe([3,  4])                       &lt;\u2013 \u0441\u0438\u0441\u0442\u0435\u043c\u043d\u044b\u0439 \u0432\u044b\u0437\u043e\u0432 \u0434\u043b\u044f \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u043a\u043e\u043d\u0432\u0435\u0435\u0440\u0430 .... clone(....) = 13727                &lt;\u2013 \u043f\u043e\u0434\u043f\u0440\u043e\u0446\u0435\u0441\u0441 \u0434\u043b\u044f \u043f\u0435\u0440\u0432\u043e\u0439 \u043a\u043e\u043c\u0430\u043d\u0434\u044b \u043a\u043e\u043d\u0432\u0435\u0435\u0440\u0430 (echo) ... [pid 13727] execve(&quot;\/bin\/echo&quot;,  [&quot;\/bin\/echo&quot;,  &quot;foo&quot;],  [\/* 61 vars *\/]  ..... [pid 13726] clone(....) = 13728    &lt;\u2013 \u043f\u043e\u0434\u043f\u0440\u043e\u0446\u0435\u0441\u0441 \u0434\u043b\u044f \u0432\u0442\u043e\u0440\u043e\u0439 \u043a\u043e\u043c\u0430\u043d\u0434\u044b (grep) \u0441\u043e\u0437\u0434\u0430\u0435\u0442\u0441\u044f \u0442\u0430\u043a \u0436\u0435 \u043e\u0441\u043d\u043e\u0432\u043d\u044b\u043c \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u043e\u043c ... [pid 13728] stat(&quot;\/home\/aikikode\/bin\/grep&quot;,    ... <\/code><\/pre>\n<p>\u0412\u0438\u0434\u043d\u043e, \u0447\u0442\u043e \u0434\u043b\u044f \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u043a\u043e\u043d\u0432\u0435\u0435\u0440\u0430 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0441\u0438\u0441\u0442\u0435\u043c\u043d\u044b\u0439 \u0432\u044b\u0437\u043e\u0432 pipe(), \u0430 \u0442\u0430\u043a\u0436\u0435, \u0447\u0442\u043e \u043e\u0431\u0430 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0430 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u044e\u0442\u0441\u044f \u043f\u0430\u0440\u0430\u043b\u043b\u0435\u043b\u044c\u043d\u043e \u0432 \u0440\u0430\u0437\u043d\u044b\u0445 \u043f\u043e\u0442\u043e\u043a\u0430\u0445.  <\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-195152","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/195152","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=195152"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/195152\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=195152"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=195152"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=195152"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}