wiki.bash-hackers.org/commands/builtin/read

576 lines
36 KiB
Plaintext
Raw Normal View History

2023-04-14 13:44:41 +02:00
<!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/commands/builtin/read?do=edit","20221006044544","http://web.archive.org/","web","/_static/",
"1665031544");
</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 read builtin command [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/20221006044544im_/https://wiki.bash-hackers.org/lib/tpl/bootstrap3/images/favicon.ico"/>
<link rel="apple-touch-icon" href="/web/20221006044544im_/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/20221006044544cs_/https://wiki.bash-hackers.org/lib/tpl/bootstrap3/assets/bootstrap/default/bootstrap.min.css"/>
<link rel="search" type="application/opensearchdescription+xml" href="/web/20221006044544/https://wiki.bash-hackers.org/lib/exe/opensearch.php" title="Bash Hackers Wiki"/>
<link rel="start" href="/"/>
<link rel="contents" href="/commands/builtin/read?do=index" title="Sitemap"/>
<link rel="manifest" href="/web/20221006044544/https://wiki.bash-hackers.org/lib/exe/manifest.php"/>
<link rel="alternate" type="application/rss+xml" title="Recent Changes" href="/web/20221006044544/https://wiki.bash-hackers.org/feed.php"/>
<link rel="alternate" type="application/rss+xml" title="Current namespace" href="/web/20221006044544/https://wiki.bash-hackers.org/feed.php?mode=list&amp;ns=commands:builtin"/>
<link rel="alternate" type="text/html" title="Plain HTML" href="/web/20221006044544/https://wiki.bash-hackers.org/_export/xhtml/commands/builtin/read"/>
<link rel="alternate" type="text/plain" title="Wiki Markup" href="/web/20221006044544/https://wiki.bash-hackers.org/_export/raw/commands/builtin/read"/>
<link rel="stylesheet" type="text/css" href="/web/20221006044544cs_/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='commands:builtin';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":"commands:builtin:read","namespace":"commands:builtin","ACT":"source","useHeadingNavigation":1,"useHeadingContent":1};
/*!]]>*/</script>
<script type="text/javascript" charset="utf-8" src="/web/20221006044544js_/https://wiki.bash-hackers.org/lib/exe/jquery.php?tseed=23f888679b4f1dc26eef34902aca964f"></script>
<script type="text/javascript" charset="utf-8" src="/web/20221006044544js_/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/20221006044544js_/https://wiki.bash-hackers.org/lib/tpl/bootstrap3/assets/bootstrap/js/bootstrap.min.js"></script>
<script type="text/javascript" src="/web/20221006044544js_/https://wiki.bash-hackers.org/lib/tpl/bootstrap3/assets/anchorjs/anchor.min.js"></script>
<script type="text/javascript" src="/web/20221006044544js_/https://wiki.bash-hackers.org/lib/tpl/bootstrap3/assets/typeahead/bootstrap3-typeahead.min.js"></script>
<script type="text/javascript" src="/web/20221006044544js_/https://wiki.bash-hackers.org/lib/tpl/bootstrap3/assets/iconify/iconify.min.js"></script>
<script type="text/javascript" src="/web/20221006044544js_/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="commands:builtin:read"><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/20221006044544/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/20221006044544im_/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/20221006044544/https://wiki.bash-hackers.org/commands/builtin/read" 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/20221006044544/https://wiki.bash-hackers.org/commands/builtin/read?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/20221006044544/https://wiki.bash-hackers.org/commands/builtin/read?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/20221006044544/https://wiki.bash-hackers.org/commands/builtin/read?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/20221006044544/https://wiki.bash-hackers.org/commands/builtin/read?do=media&amp;ns=commands%3Abuiltin" 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/20221006044544/https://wiki.bash-hackers.org/commands/builtin/read?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/20221006044544/https://wiki.bash-hackers.org/commands/builtin/read?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/20221006044544/https://wiki.bash-hackers.org/commands/builtin/read?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/20221006044544/https://wiki.bash-hackers.org/commands/builtin/read?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/20221006044544/https://wiki.bash-hackers.org/commands/builtin/read?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/20221006044544/https://wiki.bash-hackers.org/commands/builtin/read?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/20221006044544js_/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/20221006044544/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/20221006044544/https://wiki.bash-hackers.org/commands/start" class="wikilink1" title="commands:start">Commands</a></li><li itemprop="itemListElement" itemscope itemtype="http://schema.org/ListItem"><a itemprop="item" href="/web/20221006044544/https://wiki.bash-hackers.org/commands/builtin/start" class="wikilink1" title="commands:builtin:start">Builtin Commands</a></li><li class="active" itemprop="itemListElement" itemscope itemtype="http://schema.org/ListItem"><span itemprop="name"><a itemprop="item" href="/web/20221006044544/https://wiki.bash-hackers.org/commands/builtin/read" class="wikilink1" title="commands:builtin:read">The read builtin command</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">commands:builtin:read</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/20221006044544/https://wiki.bash-hackers.org/commands/builtin/read?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/20221006044544/https://wiki.bash-hackers.org/commands/builtin/read?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/20221006044544/https://wiki.bash-hackers.org/commands/builtin/read?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="commands:builtin:read"/><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="b76795eba75cca4c941333ff4f2f976d"/><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 read builtin command ======
//read something about read here!//
===== Synopsis =====
&lt;code&gt;
read [-ers] [-u &lt;FD&gt;] [-t &lt;TIMEOUT&gt;] [-p &lt;PROMPT&gt;] [-a &lt;ARRAY&gt;] [-n &lt;NCHARS&gt;] [-N &lt;NCHARS&gt;] [-d &lt;DELIM&gt;] [-i &lt;TEXT&gt;] [&lt;NAME...&gt;]
&lt;/code&gt;
===== Description =====
The ''read'' builtin reads **one line** of data (text, user input, ...) from standard input or a supplied filedescriptor number into one or more variables named by ''&lt;NAME...&gt;''.
Since Bash 4.3-alpha, ''read'' skips any ''NUL'' (ASCII code 0) characters in input.
If ''&lt;NAME...&gt;'' is given, the line is word-split using [[syntax:shellvars#IFS|IFS]] variable, and every word is assigned to one ''&lt;NAME&gt;''. The remaining words are all assigned to the last ''&lt;NAME&gt;'' if more words than variable names are present.
&lt;WRAP center round info 90%&gt;
If no ''&lt;NAME&gt;'' is given, the whole line read (without performing word-splitting!) is assigned to the shell variable [[syntax:shellvars#REPLY|REPLY]]. Then, ''REPLY'' really contains the line as it was read, without stripping pre- and postfix spaces and other things!
&lt;code&gt;
while read -r; do
printf '&quot;%s&quot;\n' &quot;$REPLY&quot;
done &lt;&lt;&lt;&quot; a line with prefix and postfix space &quot;
&lt;/code&gt;
&lt;/WRAP&gt;
If a timeout is given, or if the shell variable [[syntax:shellvars#TMOUT|TMOUT]] is set, it is counted from initially waiting for input until the completion of input (i.e. until the complete line is read). That means the timeout can occur during input, too.
==== Options ====
^Option^Description^
|''-a &lt;ARRAY&gt;''|read the data word-wise into the specified array ''&lt;ARRAY&gt;'' instead of normal variables|
|''-d &lt;DELIM&gt;''|recognize ''&lt;DELIM&gt;'' as data-end, rather than ''&lt;newline&gt;''|
|''-e''|on interactive shells: use Bash's readline interface to read the data. Since version 5.1-alpha, this can also be used on specified file descriptors using ''-u''|
|''-i &lt;STRING&gt;''|preloads the input buffer with text from ''&lt;STRING&gt;'', only works when Readline (''-e'') is used|
|''-n &lt;NCHARS&gt;''|reads ''&lt;NCHARS&gt;'' characters of input, then quits|
|''-N &lt;NCHARS&gt;''|reads ''&lt;NCHARS&gt;'' characters of input, //ignoring any delimiter//, then quits|
|''-p &lt;PROMPT&gt;''|the prompt string ''&lt;PROMPT&gt;'' is output (without a trailing automatic newline) before the read is performed|
|''-r''|raw input - **disables** interpretion of **backslash escapes** and **line-continuation** in the read data|
|''-s''|secure input - don't echo input if on a terminal (passwords!)|
|''-t &lt;TIMEOUT&gt;''|wait for data ''&lt;TIMEOUT&gt;'' seconds, then quit (exit code 1). Fractional seconds (&quot;5.33&quot;) are allowed since Bash 4. A value of 0 immediately returns and indicates if data is waiting in the exit code. Timeout is indicated by an exit code greater than 128. If timeout arrives before data is read completely (before end-of-line), the partial data is saved.|
|''-u &lt;FD&gt;''|use the filedescriptor number ''&lt;FD&gt;'' rather than ''stdin'' (0)|
When both, ''-a &lt;ARRAY&gt;'' and a variable name ''&lt;NAME&gt;'' is given, then the array is set, but not the variable.
Of course it's valid to set individual array elements without using ''-a'':
&lt;code&gt;
read MYARRAY[5]
&lt;/code&gt;
&lt;WRAP center round important 90%&gt;
Reading into array elements using the syntax above **may cause [[syntax:expansion:globs | pathname expansion]] to occur**.
Example: You are in a directory with a file named ''x1'', and you want to read into an array ''x'', index ''1'' with
&lt;code&gt;
read x[1]
&lt;/code&gt;
then pathname expansion will expand to the filename ''x1'' and break your processing!
Even worse, if ''nullglob'' is set, your array/index will disappear.
To avoid this, either **disable pathname expansion** or **quote** the array name and index:
&lt;code&gt;
read 'x[1]'
&lt;/code&gt;
&lt;/WRAP&gt;
==== Return status ====
^Status ^Reason ^
|0 |no error |
|0 |error when assigning to a read-only variable ((fixed in 4.2-rc1)) |
|2 |invalid option |
|&gt;128 |timeout (see ''-t'') |
|!=0 |invalid filedescriptor supplied to ''-u'' |
|!=0 |end-of-file reached |
==== read without -r ====
Essentially all you need to know about ''-r'' is to **ALWAYS** use it. The exact behavior you get without ''-r'' is completely useless even for weird purposes. It basically allows the escaping of input which matches something in IFS, and also escapes line continuations. It's explained pretty well in the [[http://pubs.opengroup.org/onlinepubs/9699919799/utilities/read.html#tag_20_109 | POSIX read]] spec.
&lt;code&gt;
2012-05-23 13:48:31 geirha it should only remove the backslashes, not change \n and \t and such into newlines and tabs
2012-05-23 13:49:00 ormaaj so that's what read without -r does?
2012-05-23 13:49:16 geirha no, -r doesn't remove the backslashes
2012-05-23 13:49:34 ormaaj I thought read &lt;&lt;&lt;'str' was equivalent to read -r &lt;&lt;&lt;$'str'
2012-05-23 13:49:38 geirha # read x y &lt;&lt;&lt; 'foo\ bar baz'; echo &quot;&lt;$x&gt;&lt;$y&gt;&quot;
2012-05-23 13:49:40 shbot geirha: &lt;foo bar&gt;&lt;baz&gt;
2012-05-23 13:50:32 geirha no, read without -r is mostly pointless. Damn bourne
2012-05-23 13:51:08 ormaaj So it's mostly (entirely) used to escape spaces
2012-05-23 13:51:24 ormaaj and insert newlines
2012-05-23 13:51:47 geirha ormaaj: you mostly get the same effect as using \ at the prompt
2012-05-23 13:52:04 geirha echo \&quot; outputs a &quot; , read x &lt;&lt;&lt; '\&quot;' reads a &quot;
2012-05-23 13:52:32 ormaaj oh weird
2012-05-23 13:52:46 * ormaaj struggles to think of a point to that...
2012-05-23 13:53:01 geirha ormaaj: ask Bourne :P
2012-05-23 13:53:20 geirha (not Jason)
2012-05-23 13:53:56 ormaaj hm thanks anyway :)
&lt;/code&gt;
===== Examples =====
==== Rudimentary cat replacement ====
A rudimentary replacement for the ''cat'' command: read lines of input from a file and print them on the terminal.
&lt;code&gt;
opossum() {
while read -r; do
printf &quot;%s\n&quot; &quot;$REPLY&quot;
done &lt;&quot;$1&quot;
}
&lt;/code&gt;
__**Note:**__ Here, ''read -r'' and the default ''REPLY'' is used, because we want to have the real literal line, without any mangeling. ''printf'' is used, because (depending on settings), ''echo'' may interpret some baskslash-escapes or switches (like ''-n'').
==== Press any key... ====
Remember the MSDOS ''pause'' command? Here's something similar:
&lt;code&gt;
pause() {
local dummy
read -s -r -p &quot;Press any key to continue...&quot; -n 1 dummy
}
&lt;/code&gt;
Notes:
* ''-s'' to suppress terminal echo (printing)
* ''-r'' to not interpret special characters (like waiting for a second character if somebody presses the backslash)
==== Reading Columns ====
=== Simple Split ===
Read can be used to split a string:
&lt;code&gt;
var=&quot;one two three&quot;
read -r col1 col2 col3 &lt;&lt;&lt; &quot;$var&quot;
printf &quot;col1: %s col2: %s col3 %s\n&quot; &quot;$col1&quot; &quot;$col2&quot; &quot;$col3&quot;
&lt;/code&gt;
Take care that you cannot use a pipe:
&lt;code&gt;
echo &quot;$var&quot; | read col1 col2 col3 # does not work!
printf &quot;col1: %s col2: %s col3 %s\n&quot; &quot;$col1&quot; &quot;$col2&quot; &quot;$col3&quot;
&lt;/code&gt;
Why? because the commands of the pipe run in subshells that cannot modify the parent shell. As a result, the variables
''col1'', ''col2'' and ''col3'' of the parent shell are not modified (see article: [[scripting:processtree]]).
If the variable has more fields than there are variables, the last variable get the remaining of the line:
&lt;code&gt;
read col1 col2 col3 &lt;&lt;&lt; &quot;one two three four&quot;
printf &quot;%s\n&quot; &quot;$col3&quot; #prints three four
&lt;/code&gt;
=== Changing The Separator ===
By default reads separates the line in fields using spaces or tabs. You can modify this using the //special variable// [[syntax:shellvars#IFS | IFS]],
the Internal Field Separator.
&lt;code&gt;
IFS=&quot;:&quot; read -r col1 col2 &lt;&lt;&lt; &quot;hello:world&quot;
printf &quot;col1: %s col2: %s\n&quot; &quot;$col1&quot; &quot;$col2&quot;
&lt;/code&gt;
Here we use the ''var=value command'' syntax to set the environment of ''read'' temporarily. We could have set ''IFS'' normally,
but then we would have to take care to save its value and restore it afterward (''OLD=$IFS IFS=&quot;:&quot;; read ....;IFS=$OLD'').
The default ''IFS'' is special in that 2 fields can be separated by one or more space or tab. When you set ''IFS'' to something besides whitespace (space or tab), the
fields are separated by **exactly** one character:
&lt;code&gt;
IFS=&quot;:&quot; read -r col1 col2 col3 &lt;&lt;&lt; &quot;hello::world&quot;
printf &quot;col1: %s col2: %s col3 %s\n&quot; &quot;$col1&quot; &quot;$col2&quot; &quot;$col3&quot;
&lt;/code&gt;
See how the ''&lt;nowiki&gt;::&lt;/nowiki&gt;'' in the middle infact defines an additional //empty field//.
The fields are separated by exactly one character, but the character can be different between each field:
&lt;code&gt;
IFS=&quot;:|@&quot; read -r col1 col2 col3 col4 &lt;&lt;&lt; &quot;hello:world|in@bash&quot;
printf &quot;col1: %s col2: %s col3 %s col4 %s\n&quot; &quot;$col1&quot; &quot;$col2&quot; &quot;$col3&quot; &quot;$col4&quot;
&lt;/code&gt;
==== Are you sure? ====
&lt;code&gt;
asksure() {
echo -n &quot;Are you sure (Y/N)? &quot;
while read -r -n 1 -s answer; do
if [[ $answer = [YyNn] ]]; then
[[ $answer = [Yy] ]] &amp;&amp; retval=0
[[ $answer = [Nn] ]] &amp;&amp; retval=1
break
fi
done
echo # just a final linefeed, optics...
return $retval
}
### using it
if asksure; then
echo &quot;Okay, performing rm -rf / then, master....&quot;
else
echo &quot;Pfff...&quot;
fi
&lt;/code&gt;
==== Ask for a path with a default value ====
__**Note:**__ The ''-i'' option was introduced with Bash 4
&lt;code&gt;
read -e -p &quot;Enter the path to the file: &quot; -i &quot;/usr/local/etc/&quot; FILEPATH
&lt;/code&gt;
The user will be prompted, he can just accept the default, or edit it.
==== Multichar-IFS: Parsing a simple date/time string ====
Here, ''IFS'' contains both, a colon and a space. The fields of the date/time string are recognized correctly.
&lt;code&gt;
datetime=&quot;2008:07:04 00:34:45&quot;
IFS=&quot;: &quot; read -r year month day hour minute second &lt;&lt;&lt; &quot;$datetime&quot;
&lt;/code&gt;
===== Portability considerations =====
* POSIX(r) only specified the ''-r'' option (raw read); ''-r'' is not only POSIX, you can find it in earlier Bourne source code
* POSIX(r) doesn't support arrays
* ''REPLY'' is not POSIX(r), you need to set ''IFS'' to the empty string to get the whole line for shells that don't know ''REPLY''. &lt;code&gt;
while IFS= read -r line; do
...
done &lt; text.txt
&lt;/code&gt;
===== See also =====
* Internal: [[commands:builtin:printf | The printf builtin command]]
</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="commands/builtin/read.txt">commands/builtin/read.txt</span></li><li><span class="iconify text-muted" data-icon="mdi:calendar"></span> Last modified: <span title="2021/03/18 06:46">2021/03/18 06:46</span></li><li class="text-muted">by <bdi>jarnos</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/20221006044544/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/20221006044544js_/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/20221006044544im_/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/20221006044544/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/20221006044544im_/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/20221006044544/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/20221006044544im_/https://wiki.bash-hackers.org/lib/exe/indexer.php?id=commands%3Abuiltin%3Aread&amp;1665031559" width="2" height="1" alt=""/>
</div>
</body>
</html>
<!--
FILE ARCHIVED ON 04:45:44 Oct 06, 2022 AND RETRIEVED FROM THE
INTERNET ARCHIVE ON 11:37:07 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: 219.761
exclusion.robots: 0.314
exclusion.robots.policy: 0.294
cdx.remote: 0.138
esindex: 0.018
LoadShardBlock: 183.001 (3)
PetaboxLoader3.resolve: 202.836 (4)
PetaboxLoader3.datanode: 38.16 (4)
load_resource: 91.02
-->