wiki.bash-hackers.org/syntax/keywords/coproc
2023-04-14 23:44:41 +12:00

532 lines
34 KiB
Plaintext

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" dir="ltr" class="no-js">
<head><script type="text/javascript" src="/_static/js/bundle-playback.js?v=TPXmWR5s" charset="utf-8"></script>
<script type="text/javascript" src="/_static/js/wombat.js?v=txqj7nKC" charset="utf-8"></script>
<script type="text/javascript">
__wm.init("http://web.archive.org/web");
__wm.wombat("https://wiki.bash-hackers.org/syntax/keywords/coproc?do=edit","20221203044612","http://web.archive.org/","web","/_static/",
"1670042772");
</script>
<link rel="stylesheet" type="text/css" href="/_static/css/banner-styles.css?v=S1zqJCYt" />
<link rel="stylesheet" type="text/css" href="/_static/css/iconochive.css?v=qtvMKcIJ" />
<!-- End Wayback Rewrite JS Include -->
<meta charset="UTF-8"/>
<title>The coproc keyword [Bash Hackers Wiki]</title>
<script>(function(H){H.className=H.className.replace(/\bno-js\b/,'js')})(document.documentElement)</script>
<meta name="viewport" content="width=device-width,initial-scale=1"/>
<link rel="shortcut icon" href="/web/20221203044612im_/https://wiki.bash-hackers.org/lib/tpl/bootstrap3/images/favicon.ico"/>
<link rel="apple-touch-icon" href="/web/20221203044612im_/https://wiki.bash-hackers.org/lib/tpl/bootstrap3/images/apple-touch-icon.png"/>
<meta name="generator" content="DokuWiki"/>
<meta name="robots" content="noindex,nofollow"/>
<link type="text/css" rel="stylesheet" href="/web/20221203044612cs_/https://wiki.bash-hackers.org/lib/tpl/bootstrap3/assets/bootstrap/default/bootstrap.min.css"/>
<link rel="search" type="application/opensearchdescription+xml" href="/web/20221203044612/https://wiki.bash-hackers.org/lib/exe/opensearch.php" title="Bash Hackers Wiki"/>
<link rel="start" href="/"/>
<link rel="contents" href="/syntax/keywords/coproc?do=index" title="Sitemap"/>
<link rel="manifest" href="/web/20221203044612/https://wiki.bash-hackers.org/lib/exe/manifest.php"/>
<link rel="alternate" type="application/rss+xml" title="Recent Changes" href="/web/20221203044612/https://wiki.bash-hackers.org/feed.php"/>
<link rel="alternate" type="application/rss+xml" title="Current namespace" href="/web/20221203044612/https://wiki.bash-hackers.org/feed.php?mode=list&amp;ns=syntax:keywords"/>
<link rel="alternate" type="text/html" title="Plain HTML" href="/web/20221203044612/https://wiki.bash-hackers.org/_export/xhtml/syntax/keywords/coproc"/>
<link rel="alternate" type="text/plain" title="Wiki Markup" href="/web/20221203044612/https://wiki.bash-hackers.org/_export/raw/syntax/keywords/coproc"/>
<link rel="stylesheet" type="text/css" href="/web/20221203044612cs_/https://wiki.bash-hackers.org/lib/exe/css.php?t=bootstrap3&amp;tseed=54923c3deda180f2db5bd755cd8fbf1a"/>
<!--[if gte IE 9]><!-->
<script type="text/javascript">/*<![CDATA[*/var NS='syntax:keywords';var JSINFO = {"updatable":1,"userreplace":1,"default_macro_string":"","plugins":{"edittable":{"default columnwidth":""}},"move_renameokay":false,"isadmin":0,"isauth":0,"bootstrap3":{"mode":"source","toc":[],"config":{"collapsibleSections":0,"fixedTopNavbar":1,"showSemanticPopup":0,"sidebarOnNavbar":0,"tagsOnTop":1,"tocAffix":1,"tocCollapseOnScroll":1,"tocCollapsed":0,"tocLayout":"default","useAnchorJS":1,"useAlternativeToolbarIcons":1}},"id":"syntax:keywords:coproc","namespace":"syntax:keywords","ACT":"source","useHeadingNavigation":1,"useHeadingContent":1};
/*!]]>*/</script>
<script type="text/javascript" charset="utf-8" src="/web/20221203044612js_/https://wiki.bash-hackers.org/lib/exe/jquery.php?tseed=23f888679b4f1dc26eef34902aca964f"></script>
<script type="text/javascript" charset="utf-8" src="/web/20221203044612js_/https://wiki.bash-hackers.org/lib/exe/js.php?t=bootstrap3&amp;tseed=54923c3deda180f2db5bd755cd8fbf1a"></script>
<script type="text/javascript">/*<![CDATA[*/if (typeof IconifyConfig == 'undefined') { var IconifyConfig = { 'defaultAPI' : '/lib/tpl/bootstrap3/iconify.php?prefix={prefix}&icons={icons}' } }
/*!]]>*/</script>
<script type="text/javascript" src="/web/20221203044612js_/https://wiki.bash-hackers.org/lib/tpl/bootstrap3/assets/bootstrap/js/bootstrap.min.js"></script>
<script type="text/javascript" src="/web/20221203044612js_/https://wiki.bash-hackers.org/lib/tpl/bootstrap3/assets/anchorjs/anchor.min.js"></script>
<script type="text/javascript" src="/web/20221203044612js_/https://wiki.bash-hackers.org/lib/tpl/bootstrap3/assets/typeahead/bootstrap3-typeahead.min.js"></script>
<script type="text/javascript" src="/web/20221203044612js_/https://wiki.bash-hackers.org/lib/tpl/bootstrap3/assets/iconify/iconify.min.js"></script>
<script type="text/javascript" src="/web/20221203044612js_/https://wiki.bash-hackers.org/lib/tpl/bootstrap3/assets/iconify/plugins/fa.js"></script>
<!--<![endif]-->
<style type="text/css">@media screen { body { margin-top: 65px; } #dw__toc.affix { top: 55px; position: fixed !important; } #dw__toc .nav .nav .nav { display: none; } }</style>
<!--[if lt IE 9]>
<script type="text/javascript" src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script>
<script type="text/javascript" src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
<![endif]-->
</head>
<body class="default dokuwiki mode_source tpl_bootstrap3 dw-page-on-panel dw-fluid-container" data-page-id="syntax:keywords:coproc"><div class="dokuwiki">
<header id="dokuwiki__header" class="dw-container dokuwiki container-fluid mx-5">
<!-- navbar -->
<nav id="dw__navbar" class="navbar navbar-fixed-top navbar-default" role="navigation">
<div class="dw-container container-fluid mx-5">
<div class="navbar-header">
<button class="navbar-toggle" type="button" data-toggle="collapse" data-target=".navbar-collapse">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand d-flex align-items-center" href="/web/20221203044612/https://wiki.bash-hackers.org/start" accesskey="h" title="Bash Hackers Wiki"><img id="dw__logo" class="pull-left h-100 mr-4" alt="Bash Hackers Wiki" src="/web/20221203044612im_/https://wiki.bash-hackers.org/lib/tpl/bootstrap3/images/logo.png"/><div class="pull-right"><div id="dw__title">Bash Hackers Wiki</div></div></a>
</div>
<div class="collapse navbar-collapse">
<div class="navbar-right" id="dw__navbar_items">
<!-- navbar-searchform -->
<form action="/web/20221203044612/https://wiki.bash-hackers.org/syntax/keywords/coproc" accept-charset="utf-8" class="navbar-form navbar-left search" id="dw__search" method="get" role="search">
<div class="input-group">
<input id="qsearch" autocomplete="off" type="search" placeholder="Search" value="" accesskey="f" name="q" class="form-control" title="[F]"/>
<div class="input-group-btn">
<button class="btn btn-default" type="submit" title="Search">
<span class="iconify" data-icon="mdi:magnify"></span> </button>
</div>
</div>
<input type="hidden" name="do" value="search"/>
</form>
<!-- /navbar-searchform -->
<!-- tools-menu -->
<ul class="nav navbar-nav dw-action-icon" id="dw__tools">
<li class="dropdown">
<a href="" class="dropdown-toggle" data-target="#" data-toggle="dropdown" title="" role="button" aria-haspopup="true" aria-expanded="false">
<span class="iconify" data-icon="mdi:wrench"></span> <span class="hidden-lg hidden-md hidden-sm">Tools</span> <span class="caret"></span>
</a>
<ul class="dropdown-menu tools" role="menu">
<li class="dropdown-header">
<span class="iconify" data-icon="mdi:account"></span> User Tools </li>
<li class="action"><a href="/web/20221203044612/https://wiki.bash-hackers.org/syntax/keywords/coproc?do=register" title="Register" rel="nofollow" class="menuitem register"><svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewbox="0 0 24 24"><path d="M15 14c-2.67 0-8 1.33-8 4v2h16v-2c0-2.67-5.33-4-8-4m-9-4V7H4v3H1v2h3v3h2v-3h3v-2m6 2a4 4 0 0 0 4-4 4 4 0 0 0-4-4 4 4 0 0 0-4 4 4 4 0 0 0 4 4z"/></svg><span>Register</span></a></li><li class="action"><a href="/web/20221203044612/https://wiki.bash-hackers.org/syntax/keywords/coproc?do=login&amp;sectok=" title="Log In" rel="nofollow" class="menuitem login"><svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewbox="0 0 24 24"><path d="M10 17.25V14H3v-4h7V6.75L15.25 12 10 17.25M8 2h9a2 2 0 0 1 2 2v16a2 2 0 0 1-2 2H8a2 2 0 0 1-2-2v-4h2v4h9V4H8v4H6V4a2 2 0 0 1 2-2z"/></svg><span>Log In</span></a></li>
<li class="divider" role="separator"></li>
<li class="dropdown-header">
<span class="iconify" data-icon="mdi:toolbox"></span> Site Tools </li>
<li class="action"><a href="/web/20221203044612/https://wiki.bash-hackers.org/syntax/keywords/coproc?do=recent" title="Recent Changes [r]" rel="nofollow" accesskey="r" class="menuitem recent"><svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewbox="0 0 24 24"><path d="M15 13h1.5v2.82l2.44 1.41-.75 1.3L15 16.69V13m4-5H5v11h4.67c-.43-.91-.67-1.93-.67-3a7 7 0 0 1 7-7c1.07 0 2.09.24 3 .67V8M5 21a2 2 0 0 1-2-2V5c0-1.11.89-2 2-2h1V1h2v2h8V1h2v2h1a2 2 0 0 1 2 2v6.1c1.24 1.26 2 2.99 2 4.9a7 7 0 0 1-7 7c-1.91 0-3.64-.76-4.9-2H5m11-9.85A4.85 4.85 0 0 0 11.15 16c0 2.68 2.17 4.85 4.85 4.85A4.85 4.85 0 0 0 20.85 16c0-2.68-2.17-4.85-4.85-4.85z"/></svg><span>Recent Changes</span></a></li><li class="action"><a href="/web/20221203044612/https://wiki.bash-hackers.org/syntax/keywords/coproc?do=media&amp;ns=syntax%3Akeywords" title="Media Manager" rel="nofollow" class="menuitem media"><svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewbox="0 0 24 24"><path d="M7 15l4.5-6 3.5 4.5 2.5-3L21 15m1-11h-8l-2-2H6a2 2 0 0 0-2 2v12a2 2 0 0 0 2 2h16a2 2 0 0 0 2-2V6a2 2 0 0 0-2-2M2 6H0v14a2 2 0 0 0 2 2h18v-2H2V6z"/></svg><span>Media Manager</span></a></li><li class="action"><a href="/web/20221203044612/https://wiki.bash-hackers.org/syntax/keywords/coproc?do=index" title="Sitemap [x]" rel="nofollow" accesskey="x" class="menuitem index"><svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewbox="0 0 24 24"><path d="M3 3h6v4H3V3m12 7h6v4h-6v-4m0 7h6v4h-6v-4m-2-4H7v5h6v2H5V9h2v2h6v2z"/></svg><span>Sitemap</span></a></li>
<li class="divider" role="separator"></li>
<li class="dropdown-header">
<span class="iconify" data-icon="mdi:file-document-outline"></span> Page Tools </li>
<li class="action"><a href="/web/20221203044612/https://wiki.bash-hackers.org/syntax/keywords/coproc?do=" title="Show page [v]" rel="nofollow" accesskey="v" class="menuitem show"><svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewbox="0 0 24 24"><path d="M13 9h5.5L13 3.5V9M6 2h8l6 6v12a2 2 0 0 1-2 2H6a2 2 0 0 1-2-2V4c0-1.11.89-2 2-2m9 16v-2H6v2h9m3-4v-2H6v2h12z"/></svg><span>Show page</span></a></li><li class="action"><a href="/web/20221203044612/https://wiki.bash-hackers.org/syntax/keywords/coproc?do=revisions" title="Old revisions [o]" rel="nofollow" accesskey="o" class="menuitem revs"><svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewbox="0 0 24 24"><path d="M11 7v5.11l4.71 2.79.79-1.28-4-2.37V7m0-5C8.97 2 5.91 3.92 4.27 6.77L2 4.5V11h6.5L5.75 8.25C6.96 5.73 9.5 4 12.5 4a7.5 7.5 0 0 1 7.5 7.5 7.5 7.5 0 0 1-7.5 7.5c-3.27 0-6.03-2.09-7.06-5h-2.1c1.1 4.03 4.77 7 9.16 7 5.24 0 9.5-4.25 9.5-9.5A9.5 9.5 0 0 0 12.5 2z"/></svg><span>Old revisions</span></a></li><li class="action"><a href="/web/20221203044612/https://wiki.bash-hackers.org/syntax/keywords/coproc?do=backlink" title="Backlinks" rel="nofollow" class="menuitem backlink"><svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewbox="0 0 24 24"><path d="M10.59 13.41c.41.39.41 1.03 0 1.42-.39.39-1.03.39-1.42 0a5.003 5.003 0 0 1 0-7.07l3.54-3.54a5.003 5.003 0 0 1 7.07 0 5.003 5.003 0 0 1 0 7.07l-1.49 1.49c.01-.82-.12-1.64-.4-2.42l.47-.48a2.982 2.982 0 0 0 0-4.24 2.982 2.982 0 0 0-4.24 0l-3.53 3.53a2.982 2.982 0 0 0 0 4.24m2.82-4.24c.39-.39 1.03-.39 1.42 0a5.003 5.003 0 0 1 0 7.07l-3.54 3.54a5.003 5.003 0 0 1-7.07 0 5.003 5.003 0 0 1 0-7.07l1.49-1.49c-.01.82.12 1.64.4 2.43l-.47.47a2.982 2.982 0 0 0 0 4.24 2.982 2.982 0 0 0 4.24 0l3.53-3.53a2.982 2.982 0 0 0 0-4.24.973.973 0 0 1 0-1.42z"/></svg><span>Backlinks</span></a></li><li class="action"><a href="#dokuwiki__top" title="Back to top [t]" rel="nofollow" accesskey="t" class="menuitem top"><svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewbox="0 0 24 24"><path d="M13 20h-2V8l-5.5 5.5-1.42-1.42L12 4.16l7.92 7.92-1.42 1.42L13 8v12z"/></svg><span>Back to top</span></a></li>
</ul>
</li>
</ul>
<!-- /tools-menu -->
<ul class="nav navbar-nav">
<li>
<span class="dw__actions dw-action-icon">
<a href="/web/20221203044612/https://wiki.bash-hackers.org/syntax/keywords/coproc?do=register" title="Register" rel="nofollow" class="menuitem register btn btn-success navbar-btn"><svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewbox="0 0 24 24"><path d="M15 14c-2.67 0-8 1.33-8 4v2h16v-2c0-2.67-5.33-4-8-4m-9-4V7H4v3H1v2h3v3h2v-3h3v-2m6 2a4 4 0 0 0 4-4 4 4 0 0 0-4-4 4 4 0 0 0-4 4 4 4 0 0 0 4 4z"/></svg><span class=""> Register</span></a><a href="/web/20221203044612/https://wiki.bash-hackers.org/syntax/keywords/coproc?do=login&amp;sectok=" title="Log In" rel="nofollow" class="menuitem login btn btn-default navbar-btn"><svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewbox="0 0 24 24"><path d="M10 17.25V14H3v-4h7V6.75L15.25 12 10 17.25M8 2h9a2 2 0 0 1 2 2v16a2 2 0 0 1-2 2H8a2 2 0 0 1-2-2v-4h2v4h9V4H8v4H6V4a2 2 0 0 1 2-2z"/></svg><span class=""> Log In</span></a> </span>
</li>
</ul>
</div>
</div>
</div>
</nav>
<!-- navbar -->
<div align="center">
<script async src="//web.archive.org/web/20221203044612js_/https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
<!-- BHORG_BOTTOM -->
<ins class="adsbygoogle" style="display:inline-block;width:728px;height:90px" data-ad-client="ca-pub-4658830517838678" data-ad-slot="1603598940"></ins>
<script>
(adsbygoogle = window.adsbygoogle || []).push({});
</script>
</div>
</header>
<a name="dokuwiki__top" id="dokuwiki__top"></a>
<main role="main" class="dw-container pb-5 dokuwiki container-fluid mx-5">
<div id="dokuwiki__pageheader">
<!-- breadcrumbs -->
<nav id="dw__breadcrumbs" class="small">
<hr/>
<div class="dw__youarehere">
<ol class="breadcrumb" itemscope itemtype="http://schema.org/BreadcrumbList"><li>You are here</li><li itemprop="itemListElement" itemscope itemtype="http://schema.org/ListItem"><a href="/web/20221203044612/https://wiki.bash-hackers.org/start" itemprop="item" title="start"><span itemprop="name"><span class="iconify" data-icon="mdi:home"></span></span></a></li><li itemprop="itemListElement" itemscope itemtype="http://schema.org/ListItem"><a itemprop="item" href="/web/20221203044612/https://wiki.bash-hackers.org/syntax/start" class="wikilink1" title="syntax:start">Syntax</a></li><li itemprop="itemListElement" itemscope itemtype="http://schema.org/ListItem"><a itemprop="item" href="/web/20221203044612/https://wiki.bash-hackers.org/syntax/keywords/start" class="wikilink2" title="syntax:keywords:start" rel="nofollow">keywords</a></li><li class="active" itemprop="itemListElement" itemscope itemtype="http://schema.org/ListItem"><span itemprop="name"><a itemprop="item" href="/web/20221203044612/https://wiki.bash-hackers.org/syntax/keywords/coproc" class="wikilink1" title="syntax:keywords:coproc">The coproc keyword</a></span></li></ol> </div>
<div class="dw__breadcrumbs hidden-print">
<ol class="breadcrumb"><li>Trace</li> </div>
<hr/>
</nav>
<!-- /breadcrumbs -->
<p class="text-right">
<span class="pageId ml-1 label label-primary">syntax:keywords:coproc</span> </p>
<div id="dw__msgarea" class="small">
</div>
</div>
<div class="row">
<article id="dokuwiki__content" class="col-sm-12 col-md-12 " itemscope itemtype="http://schema.org/Article" itemref="dw__license">
<!-- page-tools -->
<nav id="dw__pagetools" class="hidden-print">
<div class="tools panel panel-default">
<ul class="nav nav-stacked nav-pills text-muted">
<li class="action"><a href="/web/20221203044612/https://wiki.bash-hackers.org/syntax/keywords/coproc?do=" title="Show page [v]" rel="nofollow" accesskey="v" class="menuitem show"><svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewbox="0 0 24 24"><path d="M13 9h5.5L13 3.5V9M6 2h8l6 6v12a2 2 0 0 1-2 2H6a2 2 0 0 1-2-2V4c0-1.11.89-2 2-2m9 16v-2H6v2h9m3-4v-2H6v2h12z"/></svg><span>Show page</span></a></li><li class="action"><a href="/web/20221203044612/https://wiki.bash-hackers.org/syntax/keywords/coproc?do=revisions" title="Old revisions [o]" rel="nofollow" accesskey="o" class="menuitem revs"><svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewbox="0 0 24 24"><path d="M11 7v5.11l4.71 2.79.79-1.28-4-2.37V7m0-5C8.97 2 5.91 3.92 4.27 6.77L2 4.5V11h6.5L5.75 8.25C6.96 5.73 9.5 4 12.5 4a7.5 7.5 0 0 1 7.5 7.5 7.5 7.5 0 0 1-7.5 7.5c-3.27 0-6.03-2.09-7.06-5h-2.1c1.1 4.03 4.77 7 9.16 7 5.24 0 9.5-4.25 9.5-9.5A9.5 9.5 0 0 0 12.5 2z"/></svg><span>Old revisions</span></a></li><li class="action"><a href="/web/20221203044612/https://wiki.bash-hackers.org/syntax/keywords/coproc?do=backlink" title="Backlinks" rel="nofollow" class="menuitem backlink"><svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewbox="0 0 24 24"><path d="M10.59 13.41c.41.39.41 1.03 0 1.42-.39.39-1.03.39-1.42 0a5.003 5.003 0 0 1 0-7.07l3.54-3.54a5.003 5.003 0 0 1 7.07 0 5.003 5.003 0 0 1 0 7.07l-1.49 1.49c.01-.82-.12-1.64-.4-2.42l.47-.48a2.982 2.982 0 0 0 0-4.24 2.982 2.982 0 0 0-4.24 0l-3.53 3.53a2.982 2.982 0 0 0 0 4.24m2.82-4.24c.39-.39 1.03-.39 1.42 0a5.003 5.003 0 0 1 0 7.07l-3.54 3.54a5.003 5.003 0 0 1-7.07 0 5.003 5.003 0 0 1 0-7.07l1.49-1.49c-.01.82.12 1.64.4 2.43l-.47.47a2.982 2.982 0 0 0 0 4.24 2.982 2.982 0 0 0 4.24 0l3.53-3.53a2.982 2.982 0 0 0 0-4.24.973.973 0 0 1 0-1.42z"/></svg><span>Backlinks</span></a></li><li class="action"><a href="#dokuwiki__top" title="Back to top [t]" rel="nofollow" accesskey="t" class="menuitem top"><svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewbox="0 0 24 24"><path d="M13 20h-2V8l-5.5 5.5-1.42-1.42L12 4.16l7.92 7.92-1.42 1.42L13 8v12z"/></svg><span>Back to top</span></a></li> </ul>
</div>
</nav>
<!-- /page-tools -->
<div class="panel panel-default px-3 py-2" itemprop="articleBody">
<div class="page panel-body">
<div class="dw-content-page "><!-- content --><div class="dw-content"><p>
This page is read only. You can view the source, but not change it. Ask your administrator if you think this is wrong.
</p>
<div class="editBox" role="application">
<div class="toolbar group">
<div id="draft__status" class="draft__status"></div>
<div id="tool__bar" class="tool__bar"></div>
</div>
<form id="dw__editform" method="post" action="" accept-charset="utf-8" class=" form-inline"><div class="no">
<input type="hidden" name="sectok" value=""/><input type="hidden" name="id" value="syntax:keywords:coproc"/><input type="hidden" name="rev" value="0"/><input type="hidden" name="date" value="0"/><input type="hidden" name="prefix" value="."/><input type="hidden" name="suffix" value=""/><input type="hidden" name="changecheck" value="573cf2e4baea6f3f88e36298557a09d0"/><input type="hidden" name="target" value="section"/><textarea name="wikitext" id="wiki__text" dir="auto" class="edit form-control" cols="80" rows="10" tabindex="1" readonly="readonly">
====== The coproc keyword ======
===== Synopsis =====
&lt;code&gt;
coproc [NAME] command [redirections]
&lt;/code&gt;
===== Description =====
Bash 4.0 introduced //coprocesses//, a feature certainly familiar to ksh users. The ''coproc'' keyword starts a command as a background job, setting up pipes connected to both its stdin and stdout so that you can interact with it bidirectionally. Optionally, the co-process can have a name ''NAME''. If ''NAME'' is given, the command that follows **must be a compound command**. If no ''NAME'' is given, then the command can be either simple or compound.
The process ID of the shell spawned to execute the coprocess is available through the value of the variable named by ''NAME'' followed by a ''_PID'' suffix. For example, the variable name used to store the PID of a coproc started with no ''NAME'' given would be ''COPROC_PID'' (because ''COPROC'' is the default ''NAME''). [[commands:builtin:wait]] may be used to wait for the coprocess to terminate. Additionally, coprocesses may be manipulated through their ''jobspec''.
==== Return status ====
The return status of a coprocess is the exit status of its command.
==== Redirections ====
The optional redirections are applied after the pipes have been set up. Some examples:
&lt;code bash&gt;
# redirecting stderr in the pipe
$ coproc { ls thisfiledoesntexist; read; } 2&gt;&amp;1
[2] 23084
$ IFS= read -ru ${COPROC[0]} x; printf '%s\n' &quot;$x&quot;
ls: cannot access thisfiledoesntexist: No such file or directory
&lt;/code&gt;
&lt;code bash&gt;
#let the output of the coprocess go to stdout
$ { coproc mycoproc { awk '{print &quot;foo&quot; $0;fflush()}'; } &gt;&amp;3; } 3&gt;&amp;1
[2] 23092
$ echo bar &gt;&amp;${mycoproc[1]}
$ foobar
&lt;/code&gt;
Here we need to save the previous file descriptor of stdout, because by the time we redirect the fds of the coprocess, stdout has already been redirected to the pipe.
==== Pitfalls ====
=== Avoid the final pipeline subshell ===
The traditional Ksh workaround to avoid the subshell when doing ''command | while read'' is to use a coprocess. Unfortunately, Bash's behavior differs.
In Ksh you would do:
&lt;code bash&gt;
# ksh93 or mksh/pdksh derivatives
ls |&amp; # start a coprocess
while IFS= read -rp file; do print -r -- &quot;$file&quot;; done # read its output
&lt;/code&gt;
In bash:
&lt;code bash&gt;
#DOESN'T WORK
$ coproc ls
[1] 23232
$ while IFS= read -ru ${COPROC[0]} line; do printf '%s\n' &quot;$line&quot;; done
bash: read: line: invalid file descriptor specification
[1]+ Done coproc COPROC ls
&lt;/code&gt;
By the time we start reading from the output of the coprocess, the file descriptor has been closed.
See [[http://mywiki.wooledge.org/BashFAQ/024 | this FAQ entry on Greg's wiki]] for other pipeline subshell workarounds.
=== Buffering ===
In the first example, we GNU awk's ''fflush()'' command. As always, when you use pipes the I/O operations are buffered. Let's see what happens with ''sed'':
&lt;code bash&gt;
$ coproc sed s/^/foo/
[1] 22981
$ echo bar &gt;&amp;${COPROC[1]}
$ read -t 3 -ru ${COPROC[0]} _; (( $? &gt; 127 )) &amp;&amp; echo &quot;nothing read&quot;
nothing read
&lt;/code&gt;
Even though this example is the same as the first ''awk'' example, the ''read'' doesn't return because the output is waiting in a buffer.
See [[http://mywiki.wooledge.org/BashFAQ/009 | this faq entry on Greg's wiki]] for some workarounds and more information on buffering issues.
=== background processes ===
A coprocess' file descriptors are accessible only to the process from which the ''coproc'' was started. They are not inherited by subshells.
Here is a not-so-meaningful illustration. Suppose we want to continuously read the output of a coprocess and ''echo'' the result:
&lt;code bash&gt;
#NOT WORKING
$ coproc awk '{print &quot;foo&quot; $0;fflush()}'
[2] 23100
$ while IFS= read -ru ${COPROC[0]} x; do printf '%s\n' &quot;$x&quot;; done &amp;
[3] 23104
bash: line 243: read: 61: invalid file descriptor: Bad file descriptor
&lt;/code&gt;
This fails because the file descriptors created by the parent are not available to the subshell created by &amp;.
A possible workaround:
&lt;code bash&gt;
#WARNING: for illustration purpose ONLY
# this is not the way to make the coprocess print its output
# to stdout, see the redirections above.
$ coproc awk '{print &quot;foo&quot; $0;fflush()}'
[2] 23109
$ exec 3&lt;&amp;${COPROC[0]}
$ while IFS= read -ru 3 x; do printf '%s\n' &quot;$x&quot;; done &amp;
[3] 23110
$ echo bar &gt;&amp;${COPROC[1]}
$ foobar
&lt;/code&gt;
Here, fd 3 is inherited.
===== Examples =====
==== Anonymous Coprocess ====
Unlike ksh, Bash doesn't have true anonymous coprocesses. Instead, Bash assigns FDs to a default array named ''COPROC'' if no ''NAME'' is supplied. Here's an example:
&lt;code bash&gt;
$ coproc awk '{print &quot;foo&quot; $0;fflush()}'
[1] 22978
&lt;/code&gt;
This command starts in the background, and ''coproc'' returns immediately. Two new file descriptors are now available via the ''COPROC'' array. We can send data to our command:
&lt;code bash&gt;
$ echo bar &gt;&amp;${COPROC[1]}
&lt;/code&gt;
And then read its output:
&lt;code bash&gt;
$ IFS= read -ru ${COPROC[0]} x; printf '%s\n' &quot;$x&quot;
foobar
&lt;/code&gt;
When we don't need our command anymore, we can kill it via its pid:
&lt;code&gt;
$ kill $COPROC_PID
$
[1]+ Terminated coproc COPROC awk '{print &quot;foo&quot; $0;fflush()}'
&lt;/code&gt;
==== Named Coprocess ====
Using a named coprocess is simple. We just need a compound command (like when defining a function), and the resulting FDs will be assigned to the indexed array ''NAME'' we supply instead.
&lt;code bash&gt;
$ coproc mycoproc { awk '{print &quot;foo&quot; $0;fflush()}' ;}
[1] 23058
$ echo bar &gt;&amp;${mycoproc[1]}
$ IFS= read -ru ${mycoproc[0]} x; printf '%s\n' &quot;$x&quot;
foobar
$ kill $mycoproc_PID
$
[1]+ Terminated coproc mycoproc { awk '{print &quot;foo&quot; $0;fflush()}'; }
&lt;/code&gt;
==== Redirecting the output of a script to a file and to the screen ====
&lt;code bash&gt;
#!/bin/bash
# we start tee in the background
# redirecting its output to the stdout of the script
{ coproc tee { tee logfile ;} &gt;&amp;3 ;} 3&gt;&amp;1
# we redirect stding and stdout of the script to our coprocess
exec &gt;&amp;${tee[1]} 2&gt;&amp;1
&lt;/code&gt;
===== Portability considerations =====
* The ''coproc'' keyword is not specified by POSIX(R)
* The ''coproc'' keyword appeared in Bash version 4.0-alpha
* The ''-p'' option to Bash's ''print'' loadable is a NOOP and not connected to Bash coprocesses in any way. It is only recognized as an option for ksh compatibility, and has no effect.
* The ''-p'' option to Bash's ''[[commands:builtin:read | read]]'' builtin conflicts with that of all kshes and zsh. The equivalent in those shells is to add a ''\?prompt'' suffix to the first variable name argument to ''read''. i.e., if the first variable name given contains a ''?'' character, the remainder of the argument is used as the prompt string. Since this feature is pointless and redundant, I suggest not using it in either shell. Simply precede the ''read'' command with a ''printf %s prompt &gt;&amp;2''.
==== Other shells ====
ksh93, mksh, zsh, and Bash all support something called &quot;coprocesses&quot; which all do approximately the same thing. ksh93 and mksh have virtually identical syntax and semantics for coprocs. A //list// operator: ''|&amp;'' is added to the language which runs the preceding //pipeline// as a coprocess (This is another reason not to use the special ''|&amp;'' pipe operator in Bash -- its syntax is conflicting). The ''-p'' option to the ''read'' and ''print'' builtins can then be used to read and write to the pipe of the coprocess (whose FD isn't yet known). Special redirects are added to move the last spawned coprocess to a different FD: ''&lt;&amp;p'' and ''&gt;&amp;p'', at which point it can be accessed at the new FD using ordinary redirection, and another coprocess may then be started, again using ''|&amp;''.
zsh coprocesses are very similar to ksh except in the way they are started. zsh adds the shell reserved word ''coproc'' to the pipeline syntax (similar to the way Bash's ''time'' keyword works), so that the pipeline that follows is started as a coproc. The coproc's input and output FDs can then be accessed and moved using the same ''read''/''print'' ''-p'' and redirects used by the ksh shells.
It is unfortunate that Bash chose to go against existing practice in their coproc implementation, especially considering it was the last of the major shells to incorporate this feature. However, Bash's method accomplishes the same without requiring nearly as much additional syntax. The ''coproc'' keyword is easy enough to wrap in a function such that it takes Bash code as an ordinary argument and/or stdin like ''eval''. Coprocess functionality in other shells can be similarly wrapped to create a ''COPROC'' array automatically.
==== Only one coprocess at a time ====
The title says it all, complain to the bug-bash mailing list if you want more. See http://lists.gnu.org/archive/html/bug-bash/2011-04/msg00056.html for more details
The ability to use multiple coprocesses in Bash is considered &quot;experimental&quot;. Bash will throw an error if you attempt to start more than one. This may be overridden at compile-time with the ''MULTIPLE_COPROCS'' option. However, at this time there are still issues -- see the above mailing list discussion.
===== See also =====
* [[http://www.ict.griffith.edu.au/anthony/info/shell/co-processes.hints|Anthony Thyssen's Coprocess Hints]] - excellent summary of everything around the topic</textarea>
<div id="wiki__editbar" class="editBar">
<div id="size__ctl">
</div>
</div>
</div></form>
</div>
</div><!-- /content --></div>
</div>
</div>
<div class="small text-right">
<span class="docInfo">
<ul class="list-inline"><li><span class="iconify text-muted" data-icon="mdi:file-document-outline"></span> <span title="syntax/keywords/coproc.txt">syntax/keywords/coproc.txt</span></li><li><span class="iconify text-muted" data-icon="mdi:calendar"></span> Last modified: <span title="2013/04/14 12:36">2013/04/14 12:36</span></li><li class="text-muted">by <bdi>thebonsai</bdi></li></ul> </span>
</div>
</article>
</div>
</main>
<footer id="dw__footer" class="dw-container py-5 dokuwiki container-fluid">
<hr/>
<div align="center">
<h3><a target="_blank" href="http://web.archive.org/web/20221203044612/http://www.performing-databases.com/">This site is supported by Performing Databases - your experts for database administration</a></h3>
</div>
<hr/>
<div align="center">
<script async src="//web.archive.org/web/20221203044612js_/https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
<!-- BHORG_BOTTOM -->
<ins class="adsbygoogle" style="display:inline-block;width:728px;height:90px" data-ad-client="ca-pub-4658830517838678" data-ad-slot="1603598940"></ins>
<script>
(adsbygoogle = window.adsbygoogle || []).push({});
</script>
</div>
<!-- footer -->
<div class="dw-container small container-fluid mx-5">
<div class="footer-dw-title">
<div class="media">
<div class="media-left">
<img src="/web/20221203044612im_/https://wiki.bash-hackers.org/lib/tpl/bootstrap3/images/logo.png" alt="Bash Hackers Wiki" class="media-object" style="height:32px"/>
</div>
<div class="media-body">
<div class="row">
<div class="col-sm-2">
<h4 class="media-heading">Bash Hackers Wiki</h4>
<p>
</p>
</div>
<div class="col-sm-10">
</div>
</div>
</div>
</div>
</div>
<div class="footer-license row">
<hr/>
<div id="dw__license" class="col-sm-6">
<p>
<a href="http://web.archive.org/web/20221203044612/http://www.gnu.org/licenses/fdl-1.3.html" title="GNU Free Documentation License 1.3" target="" itemscope itemtype="http://schema.org/CreativeWork" itemprop="license" rel="license" class="license"><img src="/web/20221203044612im_/https://wiki.bash-hackers.org/lib/tpl/bootstrap3/images/license/gnufdl.png" width="24" height="24" alt="gnufdl"/> </a> </p>
<p class="small">
Except where otherwise noted, content on this wiki is licensed under the following license:<br/><a href="http://web.archive.org/web/20221203044612/http://www.gnu.org/licenses/fdl-1.3.html" title="GNU Free Documentation License 1.3" target="" itemscope itemtype="http://schema.org/CreativeWork" itemprop="license" rel="license" class="license">GNU Free Documentation License 1.3</a> </p>
</div>
<div class="col-sm-6">
</div>
</div>
</div>
<!-- /footer -->
</footer>
<a href="#dokuwiki__top" class="back-to-top hidden-print btn btn-default" title="skip to content" accesskey="t">
<span class="iconify" data-icon="mdi:chevron-up"></span> </a>
<div id="screen__mode"> <span class="visible-xs-block"></span>
<span class="visible-sm-block"></span>
<span class="visible-md-block"></span>
<span class="visible-lg-block"></span>
</div>
<img src="/web/20221203044612im_/https://wiki.bash-hackers.org/lib/exe/indexer.php?id=syntax%3Akeywords%3Acoproc&amp;1670042799" width="2" height="1" alt=""/>
</div>
</body>
</html>
<!--
FILE ARCHIVED ON 04:46:12 Dec 03, 2022 AND RETRIEVED FROM THE
INTERNET ARCHIVE ON 11:37:01 Apr 14, 2023.
JAVASCRIPT APPENDED BY WAYBACK MACHINE, COPYRIGHT INTERNET ARCHIVE.
ALL OTHER CONTENT MAY ALSO BE PROTECTED BY COPYRIGHT (17 U.S.C.
SECTION 108(a)(3)).
-->
<!--
playback timings (ms):
captures_list: 1082.604
exclusion.robots: 0.123
exclusion.robots.policy: 0.115
cdx.remote: 0.058
esindex: 0.008
LoadShardBlock: 1057.21 (3)
PetaboxLoader3.datanode: 90.044 (4)
load_resource: 280.944
PetaboxLoader3.resolve: 257.062
-->