mirror of
https://github.com/rawiriblundell/wiki.bash-hackers.org
synced 2024-12-26 06:20:41 +01:00
691 lines
44 KiB
Plaintext
691 lines
44 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/commands/builtin/printf?do=edit","20220929100731","http://web.archive.org/","web","/_static/",
|
||
|
"1664446051");
|
||
|
</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 printf 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/20220929100731im_/https://wiki.bash-hackers.org/lib/tpl/bootstrap3/images/favicon.ico"/>
|
||
|
<link rel="apple-touch-icon" href="/web/20220929100731im_/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/20220929100731cs_/https://wiki.bash-hackers.org/lib/tpl/bootstrap3/assets/bootstrap/default/bootstrap.min.css"/>
|
||
|
<link rel="search" type="application/opensearchdescription+xml" href="/web/20220929100731/https://wiki.bash-hackers.org/lib/exe/opensearch.php" title="Bash Hackers Wiki"/>
|
||
|
<link rel="start" href="/"/>
|
||
|
<link rel="contents" href="/commands/builtin/printf?do=index" title="Sitemap"/>
|
||
|
<link rel="manifest" href="/web/20220929100731/https://wiki.bash-hackers.org/lib/exe/manifest.php"/>
|
||
|
<link rel="alternate" type="application/rss+xml" title="Recent Changes" href="/web/20220929100731/https://wiki.bash-hackers.org/feed.php"/>
|
||
|
<link rel="alternate" type="application/rss+xml" title="Current namespace" href="/web/20220929100731/https://wiki.bash-hackers.org/feed.php?mode=list&ns=commands:builtin"/>
|
||
|
<link rel="alternate" type="text/html" title="Plain HTML" href="/web/20220929100731/https://wiki.bash-hackers.org/_export/xhtml/commands/builtin/printf"/>
|
||
|
<link rel="alternate" type="text/plain" title="Wiki Markup" href="/web/20220929100731/https://wiki.bash-hackers.org/_export/raw/commands/builtin/printf"/>
|
||
|
<link rel="stylesheet" type="text/css" href="/web/20220929100731cs_/https://wiki.bash-hackers.org/lib/exe/css.php?t=bootstrap3&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:printf","namespace":"commands:builtin","ACT":"source","useHeadingNavigation":1,"useHeadingContent":1};
|
||
|
/*!]]>*/</script>
|
||
|
<script type="text/javascript" charset="utf-8" src="/web/20220929100731js_/https://wiki.bash-hackers.org/lib/exe/jquery.php?tseed=23f888679b4f1dc26eef34902aca964f"></script>
|
||
|
<script type="text/javascript" charset="utf-8" src="/web/20220929100731js_/https://wiki.bash-hackers.org/lib/exe/js.php?t=bootstrap3&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/20220929100731js_/https://wiki.bash-hackers.org/lib/tpl/bootstrap3/assets/bootstrap/js/bootstrap.min.js"></script>
|
||
|
<script type="text/javascript" src="/web/20220929100731js_/https://wiki.bash-hackers.org/lib/tpl/bootstrap3/assets/anchorjs/anchor.min.js"></script>
|
||
|
<script type="text/javascript" src="/web/20220929100731js_/https://wiki.bash-hackers.org/lib/tpl/bootstrap3/assets/typeahead/bootstrap3-typeahead.min.js"></script>
|
||
|
<script type="text/javascript" src="/web/20220929100731js_/https://wiki.bash-hackers.org/lib/tpl/bootstrap3/assets/iconify/iconify.min.js"></script>
|
||
|
<script type="text/javascript" src="/web/20220929100731js_/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:printf"><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/20220929100731/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/20220929100731im_/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/20220929100731/https://wiki.bash-hackers.org/commands/builtin/printf" 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/20220929100731/https://wiki.bash-hackers.org/commands/builtin/printf?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/20220929100731/https://wiki.bash-hackers.org/commands/builtin/printf?do=login&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/20220929100731/https://wiki.bash-hackers.org/commands/builtin/printf?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/20220929100731/https://wiki.bash-hackers.org/commands/builtin/printf?do=media&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/20220929100731/https://wiki.bash-hackers.org/commands/builtin/printf?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/20220929100731/https://wiki.bash-hackers.org/commands/builtin/printf?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/20220929100731/https://wiki.bash-hackers.org/commands/builtin/printf?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/20220929100731/https://wiki.bash-hackers.org/commands/builtin/printf?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/20220929100731/https://wiki.bash-hackers.org/commands/builtin/printf?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/20220929100731/https://wiki.bash-hackers.org/commands/builtin/printf?do=login&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/20220929100731js_/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/20220929100731/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/20220929100731/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/20220929100731/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/20220929100731/https://wiki.bash-hackers.org/commands/builtin/printf" class="wikilink1" title="commands:builtin:printf">The printf 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:printf</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/20220929100731/https://wiki.bash-hackers.org/commands/builtin/printf?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/20220929100731/https://wiki.bash-hackers.org/commands/builtin/printf?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/20220929100731/https://wiki.bash-hackers.org/commands/builtin/printf?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:printf"/><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="3358177f5509e1ad7b8e1a33368706fb"/><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 printf command ======
|
||
|
|
||
|
<div center round todo box 70%>
|
||
|
FIXME Stranger, this is a very big topic that needs experience - please fill in missing information, extend the descriptions, and correct the details if you can!
|
||
|
</div>
|
||
|
<div center round tip 70%>
|
||
|
__**Attention:**__ This is about the Bash-builtin command ''printf'' - however, the description should be nearly identical for an external command that follows POSIX(r).
|
||
|
|
||
|
[[http://www.gnu.org/software/gawk/manual/gawk.html#Printf|GNU Awk]] expects a comma after the format string and between each of the arguments of a **printf** command. For examples, see: [[printf?&#using_printf_inside_of_awk|code snippet]].
|
||
|
</div>
|
||
|
|
||
|
Unlike other documentations, I don't want to redirect you to the manual page for the ''printf()'' C function family. However, if you're more experienced, that should be the most detailed description for the format strings and modifiers.
|
||
|
|
||
|
Due to conflicting historical implementations of the ''echo'' command, POSIX(r) recommends that ''printf'' is preferred over ''[[commands:builtin:echo|echo]]''.
|
||
|
|
||
|
===== General =====
|
||
|
|
||
|
The ''printf'' command provides a method to print preformatted text similar to the ''printf()'' system interface (C function). It's meant as successor for ''echo'' and has far more features and possibilities.
|
||
|
|
||
|
Beside other reasons, POSIX(r) has a very good argument to recommend it: Both historical main flavours of the ''echo'' command are mutual exclusive, they collide. A "new" command had to be invented to solve the issue.
|
||
|
|
||
|
===== Syntax =====
|
||
|
|
||
|
<code>
|
||
|
printf <FORMAT> <ARGUMENTS...>
|
||
|
</code>
|
||
|
|
||
|
The text format is given in ''<FORMAT>'', while all arguments the formatstring may point to are given after that, here, indicated by ''<ARGUMENTS...>''.
|
||
|
|
||
|
Thus, a typical ''printf''-call looks like:
|
||
|
<code>
|
||
|
printf "Surname: %s\nName: %s\n" "$SURNAME" "$FIRSTNAME"
|
||
|
</code>
|
||
|
where ''"Surname: %s\nName: %s\n"'' is the format specification, and the two variables are passed as arguments, the ''%s'' in the formatstring points to (for every format specifier you give, ''printf'' awaits one argument!).
|
||
|
|
||
|
==== Options ====
|
||
|
|
||
|
|''-v VAR''|If given, the output is assigned to the variable ''VAR'' instead of printed to ''stdout'' (comparable to ''sprintf()'' in some way)|
|
||
|
|
||
|
The ''-v'' Option can't assign directly to array indexes in Bash versions older than Bash 4.1.
|
||
|
|
||
|
<note warning>
|
||
|
In versions newer than 4.1, one must be careful when performing expansions into the first non-option argument of printf as this opens up the possibility of an easy code injection vulnerability.
|
||
|
<code>
|
||
|
$ var='-vx[$(echo hi >&2)]'; printf "$var" hi; declare -p x
|
||
|
hi
|
||
|
declare -a x='([0]="hi")'
|
||
|
</code>
|
||
|
...where the echo can of course be replaced with any arbitrary command. If you must, either specify a hard-coded format string or use <nowiki>--</nowiki> to signal the end of options. The exact same issue also applies to [[commands/builtin/read | read]], and a similar one to [[commands/builtin/mapfile | mapfile]], though performing expansions into their arguments is less common.
|
||
|
</note>
|
||
|
|
||
|
==== Arguments ====
|
||
|
|
||
|
Of course in shell-meaning the arguments are just strings, however, the common C-notations plus some additions for number-constants are recognized to give a number-argument to ''printf'':
|
||
|
|
||
|
^Number-Format^Description^
|
||
|
|''N''|A normal decimal number|
|
||
|
|''0N''|An octal number|
|
||
|
|''0xN''|A hexadecimal number|
|
||
|
|''0XN''|A hexadecimal number|
|
||
|
|''"X''|(a literal double-quote infront of a character): interpreted as number (underlying codeset) **don't forget escaping**|
|
||
|
|''<nowiki>'X</nowiki>''|(a literal single-quote infront of a character): interpreted as number (underlying codeset) **don't forget escaping**|
|
||
|
|
||
|
__**If more arguments than format specifiers**__ are present, then the format string is re-used until the last argument is interpreted. If fewer format specifiers than arguments are present, then number-formats are set to zero, while string-formats are set to null (empty).
|
||
|
|
||
|
Take care to avoid [[syntax:expansion:wordsplit | word splitting]], as accidentally passing the wrong number of arguments can produce wildly different and unexpected results. See [[syntax:words | this article]].
|
||
|
|
||
|
<note warning>
|
||
|
__**Again, attention:**__ When a numerical format expects a number, the internal ''printf''-command will use the common Bash arithmetic rules regarding the base. A command like the following example **will** throw an error, since ''08'' is not a valid octal number (''00'' to ''07''!):
|
||
|
<code>
|
||
|
printf '%d\n' 08
|
||
|
</code>
|
||
|
</note>
|
||
|
|
||
|
==== Format strings ====
|
||
|
|
||
|
The format string interpretion is derived from the C ''printf()'' function family. Only format specifiers that end in one of the letters ''diouxXfeEgGaAcs'' are recognized.
|
||
|
|
||
|
To print a literal ''%'' (percent-sign), use ''<nowiki>%%</nowiki>'' in the format string.
|
||
|
|
||
|
__**Again:**__ Every format specifier expects an associated argument provided!
|
||
|
|
||
|
These specifiers have different names, depending who you ask. But they all mean the same: A placeholder for data with a specified format:
|
||
|
* format placeholder
|
||
|
* conversion specification
|
||
|
* formatting token
|
||
|
* ...
|
||
|
|
||
|
^Format^Description^
|
||
|
|''%b''|Print the associated argument while interpreting backslash escapes in there|
|
||
|
|''%q''|Print the associated argument **shell-quoted**, reusable as input|
|
||
|
|''%d''|Print the associated argument as **signed decimal** number|
|
||
|
|''%i''|Same as ''%d''|
|
||
|
|''%o''|Print the associated argument as **unsigned octal** number|
|
||
|
|''%u''|Print the associated argument as **unsigned decimal** number|
|
||
|
|''%x''|Print the associated argument as **unsigned hexadecimal** number with lower-case hex-digits (a-f)|
|
||
|
|''%X''|Same as ''%x'', but with upper-case hex-digits (A-F)|
|
||
|
|''%f''|Interpret and print the associated argument as **floating point** number|
|
||
|
|''%e''|Interpret the associated argument as **double**, and print it in ''<N>±e<N>'' format|
|
||
|
|''%E''|Same as ''%e'', but with an upper-case ''E'' in the printed format|
|
||
|
|''%g''|Interprets the associated argument as **double**, but prints it like ''%f'' or ''%e''|
|
||
|
|''%G''|Same as ''%g'', but print it like ''%E''|
|
||
|
|''%c''|Interprets the associated argument as **char**: only the first character of a given argument is printed|
|
||
|
|''%s''|Interprets the associated argument literally as string|
|
||
|
|''%n''|Assigns the number of characters printed so far to the variable named in the corresponding argument. Can't specify an array index. If the given name is already an array, the value is assigned to the zeroth element.|
|
||
|
|''%a''|Interprets the associated argument as **double**, and prints it in the form of a C99 [[http://www.exploringbinary.com/hexadecimal-floating-point-constants/ | hexadecimal floating-point literal]].|
|
||
|
|''%A''|Same as ''%a'', but print it like ''%E''|
|
||
|
|''%(FORMAT)T''|output the date-time string resulting from using ''FORMAT'' as a format string for ''strftime(3)''. The associated argument is the number of seconds since Epoch, or ''-1'' (current time) or ''-2'' (shell startup time). If no corresponding argument is supplies, the current time is used as default|
|
||
|
|''%%''|No conversion is done. Produces a ''%'' (percent sign)|
|
||
|
|
||
|
Some of the mentioned format specifiers can modify their behaviour by getting a format modifier:
|
||
|
==== Modifiers ====
|
||
|
|
||
|
To be more flexible in the output of numbers and strings, the ''printf'' command allows format modifiers. These are specified **between** the introductory ''%'' and the character that specifies the format:
|
||
|
<code>printf "%50s\n" "This field is 50 characters wide..."</code>
|
||
|
|
||
|
=== Field and printing modifiers ===
|
||
|
|
||
|
^Field output format^^
|
||
|
|''<N>''|**Any number**: Specifies a **minimum field width**, if the text to print is shorter, it's padded with spaces, if the text is longer, the field is expanded|
|
||
|
|''.''|**The dot**: Together with a field width, the field is **not** expanded when the text is longer, the text is truncated instead. "''%.s''" is an undocumented equivalent for "''%.0s''", which will force a field width of zero, effectively hiding the field from output|
|
||
|
|''*''|**The asterisk**: the width is given as argument before the string or number. Usage (the "''*''" corresponds to the "''20''"): ''printf "%*s\n" 20 "test string"''|
|
||
|
|''#''|"Alternative format" for numbers: see table below|
|
||
|
|''-''|**Left-bound** text printing in the field (standard is **right-bound**)|
|
||
|
|''0''|Pads numbers with zeros, not spaces|
|
||
|
|''<space>''|Pad a positive number with a space, where a minus (''-'') is for negative numbers|
|
||
|
|''+''|Prints all numbers **signed** (''+'' for positive, ''-'' for negative)|
|
||
|
|''<nowiki>'</nowiki>''|For decimal conversions, the thousands grouping separator is applied to the integer portion of the output according to the current LC_NUMERIC|
|
||
|
|
||
|
__**The "alternative format" modifier ''#'':**__
|
||
|
|
||
|
^Alternative Format^^
|
||
|
|''%#o''|The octal number is printed with a leading zero, unless it's zero itself|
|
||
|
|''%#x'', ''%#X''|The hex number is printed with a leading "''0x''"/"''0X''", unless it's zero|
|
||
|
|''%#g'', ''%#G''|The float number is printed with **trailing zeros** until the number of digits for the current precision is reached (usually trailing zeros are not printed)|
|
||
|
|all number formats except ''%d'', ''%o'', ''%x'', ''%X''|Always print a decimal point in the output, even if no digits follow it|
|
||
|
|
||
|
=== Precision ===
|
||
|
|
||
|
The precision for a floating- or double-number can be specified by using ''.<DIGITS>'', where ''<DIGITS>'' is the number of digits for precision. If ''<DIGITS>'' is an asterisk (''*''), the precision is read from the argument that precedes the number to print, like (prints 4,3000000000):
|
||
|
<code>printf "%.*f\n" 10 4,3</code>
|
||
|
The format ''.*N'' to specify the N'th argument for precision does not work in Bash.
|
||
|
|
||
|
For strings, the precision specifies the maximum number of characters to print (i.e., the maximum field width). For integers, it specifies the number of digits to print (zero-padding!).
|
||
|
|
||
|
==== Escape codes ====
|
||
|
|
||
|
These are interpreted if used anywhere in the format string, or in an argument corresponding to a ''%b'' format.
|
||
|
|
||
|
^Code^Description^
|
||
|
|''\\''|Prints the character ''\'' (backslash)|
|
||
|
|''\a''|Prints the alert character (ASCII code 7 decimal)|
|
||
|
|''\b''|Prints a backspace|
|
||
|
|''\f''|Prints a form-feed|
|
||
|
|''\n''|Prints a newline|
|
||
|
|''\r''|Prints a carriage-return|
|
||
|
|''\t''|Prints a horizontal tabulator|
|
||
|
|''\v''|Prints a vertical tabulator|
|
||
|
|''\"''|Prints a ''<nowiki>'</nowiki>''|
|
||
|
|''\?''|Prints a ''?''|
|
||
|
|''\<NNN>''|Interprets ''<NNN>'' as **octal** number and prints the corresponding character from the character set|
|
||
|
|''\0<NNN>''|same as ''\<NNN>''|
|
||
|
|''\x<NNN>''|Interprets ''<NNN>'' as **hexadecimal** number and prints the corresponding character from the character set (**3 digits**)|
|
||
|
|''\u<NNNN>''|same as ''\x<NNN>'', but **4 digits**|
|
||
|
|''\U<NNNNNNNN>''|same as ''\x<NNN>'', but **8 digits**|
|
||
|
|
||
|
The following additional escape and extra rules apply only to arguments associated with a ''%b'' format:
|
||
|
|
||
|
|''\c''|Terminate output similarly to the ''\c'' escape used by ''echo -e''. printf produces no additional output after coming across a ''\c'' escape in a ''%b'' argument.|
|
||
|
|
||
|
* Backslashes in the escapes: ''\<nowiki>'</nowiki>'', ''\"'', and ''\?'' are not removed.
|
||
|
* Octal escapes beginning with ''\0'' may contain up to four digits. (POSIX specifies up to three).
|
||
|
|
||
|
These are also respects in which ''%b'' differs from the escapes used by [[syntax/quoting#ansi_c_like_strings | $'...']] style quoting.
|
||
|
|
||
|
===== Examples =====
|
||
|
|
||
|
==== Snipplets ====
|
||
|
|
||
|
* print the decimal representation of a hexadecimal number (preserve the sign)
|
||
|
* ''printf "%d\n" 0x41''
|
||
|
* ''printf "%d\n" -0x41''
|
||
|
* ''printf "%+d\n" 0x41''
|
||
|
* print the octal representation of a decimal number
|
||
|
* ''printf "%o\n" 65''
|
||
|
* ''printf "%05o\n" 65'' (5 characters width, padded with zeros)
|
||
|
* this prints a 0, since no argument is specified
|
||
|
* ''printf "%d\n"''
|
||
|
* print the code number of the character ''A''
|
||
|
* ''printf "%d\n" \'A''
|
||
|
* ''printf "%d\n" "'A"''
|
||
|
* Generate a greeting banner and assign it to the variable ''GREETER''
|
||
|
* ''printf -v GREETER "Hello %s" "$LOGNAME"''
|
||
|
* Print a text at the end of the line, using ''tput'' to get the current line width
|
||
|
* ''printf "%*s\n" $(tput cols) "Hello world!"''
|
||
|
|
||
|
==== Small code table ====
|
||
|
|
||
|
This small loop prints all numbers from 0 to 127 in
|
||
|
* decimal
|
||
|
* octal
|
||
|
* hex
|
||
|
<code>
|
||
|
for ((x=0; x <= 127; x++)); do
|
||
|
printf '%3d | %04o | 0x%02x\n' "$x" "$x" "$x"
|
||
|
done
|
||
|
</code>
|
||
|
|
||
|
==== Ensure well-formatted MAC address ====
|
||
|
|
||
|
This code here will take a common MAC address and rewrite it into a well-known format (regarding leading zeros or upper/lowercase of the hex digits, ...):
|
||
|
|
||
|
<code>
|
||
|
the_mac="0:13:ce:7:7a:ad"
|
||
|
|
||
|
# lowercase hex digits
|
||
|
the_mac="$(printf "%02x:%02x:%02x:%02x:%02x:%02x" 0x${the_mac//:/ 0x})"
|
||
|
|
||
|
# or the uppercase-digits variant
|
||
|
the_mac="$(printf "%02X:%02X:%02X:%02X:%02X:%02X" 0x${the_mac//:/ 0x})"
|
||
|
</code>
|
||
|
|
||
|
==== Replacement echo ====
|
||
|
|
||
|
This code was found in Solaris manpage for echo(1).
|
||
|
|
||
|
Solaris version of ''/usr/bin/echo'' is equivalent to:
|
||
|
|
||
|
<code>
|
||
|
printf "%b\n" "$*"
|
||
|
</code>
|
||
|
|
||
|
Solaris ''/usr/ucb/echo'' is equivalent to:
|
||
|
|
||
|
<code>
|
||
|
if [ "X$1" = "X-n" ]
|
||
|
then
|
||
|
shift
|
||
|
printf "%s" "$*"
|
||
|
else
|
||
|
printf "%s\n" "$*"
|
||
|
fi
|
||
|
</code>
|
||
|
|
||
|
==== prargs Implementation ====
|
||
|
|
||
|
Working off the replacement echo, here is a terse implementation of prargs:
|
||
|
|
||
|
<code>
|
||
|
printf '"%b"\n' "$0" "$@" | nl -v0 -s": "
|
||
|
</code>
|
||
|
|
||
|
==== repeating a character (for example to print a line) ====
|
||
|
|
||
|
A small trick: Combining printf and parameter expansion to draw a line
|
||
|
|
||
|
<code>
|
||
|
length=40
|
||
|
printf -v line '%*s' "$length"
|
||
|
echo ${line// /-}
|
||
|
</code>
|
||
|
or:
|
||
|
<code>
|
||
|
length=40
|
||
|
eval printf -v line '%.0s-' {1..$length}
|
||
|
</code>
|
||
|
|
||
|
==== Replacement for some calls to date(1) ====
|
||
|
|
||
|
The ''%(...)T'' format string is a direct interface to ''strftime(3)''.
|
||
|
|
||
|
<code>
|
||
|
$ printf 'This is week %(%U/%Y)T.\n' -1
|
||
|
This is week 52/2010.
|
||
|
</code>
|
||
|
|
||
|
Please read the manpage of ''strftime(3)'' to get more information about the supported formats.
|
||
|
|
||
|
===== differences from awk printf =====
|
||
|
|
||
|
Awk also derives its //printf()// function from C, and therefore has similar format specifiers. However, in all versions of awk the space character is used as a string concatenation operator, so it cannot be used as an argument separator. **Arguments to awk printf must be separated by commas.** Some versions of awk do not require printf arguments to be surrounded by parentheses, but you should use them anyway to provide portability.
|
||
|
|
||
|
In the following example, the two strings are concatenated by the intervening space so that no argument remains to fill the format.
|
||
|
|
||
|
<code>
|
||
|
|
||
|
$ echo "Foo" | awk '{ printf "%s\n" $1 }'
|
||
|
awk: (FILENAME=- FNR=1) fatal: not enough arguments to satisfy format string
|
||
|
`%s
|
||
|
Foo'
|
||
|
^ ran out for this one
|
||
|
|
||
|
</code>
|
||
|
|
||
|
Simply replacing the space with a comma and adding parentheses yields correct awk syntax.
|
||
|
|
||
|
<code>
|
||
|
$ echo "Foo" | awk '{ printf( "%s\n", $1 ) }'
|
||
|
Foo
|
||
|
</code>
|
||
|
|
||
|
With appropriate metacharacter escaping the bash printf can be called from inside awk (as from perl and other languages that support shell callout) as long as you don't care about program efficiency or readability.
|
||
|
|
||
|
<code>
|
||
|
echo "Foo" | awk '{ system( "printf \"%s\\n \" \"" $1 "\"" ) }'
|
||
|
Foo
|
||
|
</code>
|
||
|
|
||
|
===== Differences from C, and portability considerations =====
|
||
|
|
||
|
* The a, A, e, E, f, F, g, and G conversions are supported by Bash, but not required by POSIX.
|
||
|
|
||
|
* There is no wide-character support (wprintf). For instance, if you use ''%c'', you're actually asking for the first byte of the argument. Likewise, the maximum field width modifier (dot) in combination with ''%s'' goes by bytes, not characters. This limits some of printf's functionality to working with ascii only. ksh93's ''printf'' supports the ''L'' modifier with ''%s'' and ''%c'' (but so far not ''%S'' or ''%C'') in order to treat precision as character width, not byte count. zsh appears to adjust itself dynamically based upon ''LANG'' and ''LC_CTYPE''. If ''LC_CTYPE=C'', zsh will throw "character not in range" errors, and otherwise supports wide characters automatically if a variable-width encoding is set for the current locale.
|
||
|
|
||
|
* Bash recognizes and skips over any characters present in the length modifiers specified by POSIX during format string parsing.
|
||
|
<code c|builtins/printf.def>
|
||
|
#define LENMODS "hjlLtz"
|
||
|
...
|
||
|
/* skip possible format modifiers */
|
||
|
modstart = fmt;
|
||
|
while (*fmt && strchr (LENMODS, *fmt))
|
||
|
fmt++;
|
||
|
</code>
|
||
|
|
||
|
* mksh has no built-in printf by default (usually). There is an unsupported compile-time option to include a very poor, basically unusable implementation. For the most part you must rely upon the system's ''/usr/bin/printf'' or equivalent. The mksh maintainer recommends using ''print''. The development version (post- R40f) adds a new parameter expansion in the form of ''${name@Q}'' which fills the role of ''printf %q'' -- expanding in a shell-escaped format.
|
||
|
|
||
|
* ksh93 optimizes builtins run from within a command substitution and which have no redirections to run in the shell's process. Therefore the ''printf -v'' functionality can be closely matched by ''var=$(printf ...)'' without a big performance hit.
|
||
|
<code>
|
||
|
# Illustrates Bash-like behavior. Redefining printf is usually unnecessary / not recommended.
|
||
|
function printf {
|
||
|
case $1 in
|
||
|
-v)
|
||
|
shift
|
||
|
nameref x=$1
|
||
|
shift
|
||
|
x=$(command printf "$@")
|
||
|
;;
|
||
|
*)
|
||
|
command printf "$@"
|
||
|
esac
|
||
|
}
|
||
|
builtin cut
|
||
|
print $$
|
||
|
printf -v 'foo[2]' '%d\n' "$(cut -d ' ' -f 1 /proc/self/stat)"
|
||
|
typeset -p foo
|
||
|
# 22461
|
||
|
# typeset -a foo=([2]=22461)
|
||
|
</code>
|
||
|
|
||
|
* The optional Bash loadable ''print'' may be useful for ksh compatibility and to overcome some of [[commands/builtin/echo | echo]]'s portability pitfalls. Bash, ksh93, and zsh's ''print'' have an ''-f'' option which takes a ''printf'' format string and applies it to the remaining arguments. Bash lists the synopsis as: ''print: print [-Rnprs] [-u unit] [-f format] [arguments]''. However, only ''-Rrnfu'' are actually functional. Internally, ''-p'' is a noop (it doesn't tie in with Bash coprocs at all), and ''-s'' only sets a flag but has no effect. ''-Cev'' are unimplemented.
|
||
|
|
||
|
* Assigning to variables: The ''printf -v'' way is slightly different to the way using command-substitution. [[syntax:expansion:cmdsubst | Command substitution]] removes trailing newlines before substituting the text, ''printf -v'' preserves all output.
|
||
|
|
||
|
===== See also =====
|
||
|
|
||
|
* SUS: [[http://pubs.opengroup.org/onlinepubs/9699919799/utilities/printf.html | printf utility]] and [[http://pubs.opengroup.org/onlinepubs/9699919799/functions/printf.html | printf() function]]
|
||
|
* [[snipplets:print_horizontal_line|Code snip: Print a horizontal line]] uses some ''printf'' examples
|
||
|
* [[BashFAQ>018 | Greg's BashFAQ 18: How can I use numbers with leading zeros in a loop, e.g., 01, 02?]]</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/printf.txt">commands/builtin/printf.txt</span></li><li><span class="iconify text-muted" data-icon="mdi:calendar"></span> Last modified: <span title="2016/11/30 15:39">2016/11/30 15:39</span></li><li class="text-muted">by <bdi>medievalist</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/20220929100731/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/20220929100731js_/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/20220929100731im_/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/20220929100731/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/20220929100731im_/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/20220929100731/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/20220929100731im_/https://wiki.bash-hackers.org/lib/exe/indexer.php?id=commands%3Abuiltin%3Aprintf&1664446065" width="2" height="1" alt=""/>
|
||
|
</div>
|
||
|
|
||
|
</body>
|
||
|
</html>
|
||
|
<!--
|
||
|
FILE ARCHIVED ON 10:07:31 Sep 29, 2022 AND RETRIEVED FROM THE
|
||
|
INTERNET ARCHIVE ON 11:37:06 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: 74.234
|
||
|
exclusion.robots: 0.107
|
||
|
exclusion.robots.policy: 0.098
|
||
|
cdx.remote: 0.054
|
||
|
esindex: 0.008
|
||
|
LoadShardBlock: 42.514 (3)
|
||
|
PetaboxLoader3.datanode: 48.383 (4)
|
||
|
load_resource: 593.66
|
||
|
PetaboxLoader3.resolve: 565.915
|
||
|
-->
|