Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > gnu.bash.bug > #16162
| Path | csiph.com!goblin2!goblin1!goblin.stu.neva.ru!usenet.stanford.edu!not-for-mail |
|---|---|
| From | Robert Elz <kre@munnari.OZ.AU> |
| Newsgroups | gnu.bash.bug |
| Subject | Re: %q with truncating size loses safeness of %q |
| Date | Sat, 18 Apr 2020 05:37:52 +0700 |
| Lines | 35 |
| Approved | bug-bash@gnu.org |
| Message-ID | <mailman.553.1587163115.3066.bug-bash@gnu.org> (permalink) |
| References | <4bacf2f0-9802-67d3-f30b-80e37d058a4a@case.edu> <CAOj-5WCqxqh=Gcda9k6y4orQaQYXPgsOgNEOVN1AdZQrkCVbtg@mail.gmail.com> <22039.1587163072@jinx.noi.kre.to> |
| NNTP-Posting-Host | lists.gnu.org |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset=us-ascii |
| X-Trace | usenet.stanford.edu 1587163115 21365 209.51.188.17 (17 Apr 2020 22:38:35 GMT) |
| X-Complaints-To | action@cs.stanford.edu |
| Cc | bug-bash@gnu.org, Sam Liddicott <sam@liddicott.com> |
| To | chet.ramey@case.edu |
| Envelope-to | bug-bash@gnu.org |
| In-Reply-To | <4bacf2f0-9802-67d3-f30b-80e37d058a4a@case.edu> |
| X-detected-operating-system | by eggs.gnu.org: GNU/Linux 3.x [generic] |
| X-Received-From | 2001:3c8:9009:181::2 |
| X-BeenThere | bug-bash@gnu.org |
| X-Mailman-Version | 2.1.23 |
| Precedence | list |
| List-Id | Bug reports for the GNU Bourne Again SHell <bug-bash.gnu.org> |
| List-Unsubscribe | <https://lists.gnu.org/mailman/options/bug-bash>, <mailto:bug-bash-request@gnu.org?subject=unsubscribe> |
| List-Archive | <https://lists.gnu.org/archive/html/bug-bash> |
| List-Post | <mailto:bug-bash@gnu.org> |
| List-Help | <mailto:bug-bash-request@gnu.org?subject=help> |
| List-Subscribe | <https://lists.gnu.org/mailman/listinfo/bug-bash>, <mailto:bug-bash-request@gnu.org?subject=subscribe> |
| X-Mailman-Original-Message-ID | <22039.1587163072@jinx.noi.kre.to> |
| X-Mailman-Original-References | <4bacf2f0-9802-67d3-f30b-80e37d058a4a@case.edu> <CAOj-5WCqxqh=Gcda9k6y4orQaQYXPgsOgNEOVN1AdZQrkCVbtg@mail.gmail.com> |
| Xref | csiph.com gnu.bash.bug:16162 |
Show key headers only | View raw
Date: Fri, 17 Apr 2020 16:12:20 -0400
From: Chet Ramey <chet.ramey@case.edu>
Message-ID: <4bacf2f0-9802-67d3-f30b-80e37d058a4a@case.edu>
| I would say this is a programmer error. The way precisions work with
| string arguments is that the argument is fetched or generated (this
| includes generating the quoted string for %q or the expanded string for
| %b) and then printf writes number of bytes (!) from that generated string
| specified by the precision.
This happens only because of the cheap way we (and I presume you)
implement things - in any rational scheme, it would take the precision
chars from the source string, and then quote them.
But that's hard - instead we just use printf to do the work, %q quotes
the arg string, and then the 'q' is changed to a 's' in the format, and
we just call printf(3) to do the work (padding, justification, ...)
The only excuse for this is pragmatics, no-one would deliberately set
out to design something quite that bogus.
The end result is as Greg said, "Don't do that", if precisions are
needed with %q do something like
printf 'echo %q%q\n' "$(printf %.2s "a'b")" ';ls'
which produces
echo a\'\;ls
which I expect is the desired result.
kre
Back to gnu.bash.bug | Previous | Next | Find similar
Re: %q with truncating size loses safeness of %q Robert Elz <kre@munnari.OZ.AU> - 2020-04-18 05:37 +0700
csiph-web