From owner-svn-src-head@freebsd.org Wed Jul 1 16:33:33 2020 Return-Path: Delivered-To: svn-src-head@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id B376F356D68; Wed, 1 Jul 2020 16:33:33 +0000 (UTC) (envelope-from fernape@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 49xmxn4GsQz4kPc; Wed, 1 Jul 2020 16:33:33 +0000 (UTC) (envelope-from fernape@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 5EF97C249; Wed, 1 Jul 2020 16:33:33 +0000 (UTC) (envelope-from fernape@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id 061GXXB2033919; Wed, 1 Jul 2020 16:33:33 GMT (envelope-from fernape@FreeBSD.org) Received: (from fernape@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id 061GXX8n033918; Wed, 1 Jul 2020 16:33:33 GMT (envelope-from fernape@FreeBSD.org) Message-Id: <202007011633.061GXX8n033918@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: fernape set sender to fernape@FreeBSD.org using -f From: =?UTF-8?Q?Fernando_Apestegu=c3=ada?= Date: Wed, 1 Jul 2020 16:33:33 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r362843 - head/usr.bin/printf X-SVN-Group: head X-SVN-Commit-Author: fernape X-SVN-Commit-Paths: head/usr.bin/printf X-SVN-Commit-Revision: 362843 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.33 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 01 Jul 2020 16:33:33 -0000 Author: fernape (ports committer) Date: Wed Jul 1 16:33:32 2020 New Revision: 362843 URL: https://svnweb.freebsd.org/changeset/base/362843 Log: printf(1): Add EXAMPLES section * Small addition with four simple examples * While here, remove three obsolete .Tn macros Approved by: manpages (gbe) Differential Revision: https://reviews.freebsd.org/D25462 Modified: head/usr.bin/printf/printf.1 Modified: head/usr.bin/printf/printf.1 ============================================================================== --- head/usr.bin/printf/printf.1 Wed Jul 1 16:18:35 2020 (r362842) +++ head/usr.bin/printf/printf.1 Wed Jul 1 16:33:32 2020 (r362843) @@ -31,7 +31,7 @@ .\" @(#)printf.1 8.1 (Berkeley) 6/6/93 .\" $FreeBSD$ .\" -.Dd July 29, 2019 +.Dd July 1, 2020 .Dt PRINTF 1 .Os .Sh NAME @@ -316,12 +316,48 @@ Consult the manual page. .Sh EXIT STATUS .Ex -std +.Sh EXAMPLES +Print the string +.Qq hello : +.Bd -literal -offset indent +$ printf "%s\en" hello +hello +.Ed +.Pp +Same as above, but notice that the format string is not quoted and hence we +do not get the expected behavior: +.Bd -literal -offset indent +$ printf %s\en hello +hellon$ +.Ed +.Pp +Print arguments forcing sign only for the first argument: +.Bd -literal -offset indent +$ printf "%+d\en%d\en%d\en" 1 -2 13 ++1 +-2 +13 +.Ed +.Pp +Same as above, but the single format string will be applied to the three +arguments: +.Bd -literal -offset indent +$ printf "%+d\en" 1 -2 13 ++1 +-2 ++13 +.Ed +.Pp +Print number using only two digits after the decimal point: +.Bd -literal -offset indent +$ printf "%.2f\en" 31.7456 +31.75 +.Ed .Sh COMPATIBILITY The traditional .Bx behavior of converting arguments of numeric formats not beginning -with a digit to the -.Tn ASCII +with a digit to the ASCII code of the first character is not supported. .Sh SEE ALSO .Xr builtin 1 , @@ -343,8 +379,7 @@ It is modeled after the standard library function, .Xr printf 3 . .Sh CAVEATS -.Tn ANSI -hexadecimal character constants were deliberately not provided. +ANSI hexadecimal character constants were deliberately not provided. .Pp Trying to print a dash ("-") as the first character causes .Nm @@ -364,10 +399,8 @@ and formats with a precision may not operate as expected. .Sh BUGS -Since the floating point numbers are translated from -.Tn ASCII -to floating-point and -then back again, floating-point precision may be lost. +Since the floating point numbers are translated from ASCII +to floating-point and then back again, floating-point precision may be lost. (By default, the number is translated to an IEEE-754 double-precision value before being printed. The