Path: csiph.com!xmission!news.snarked.org!news.linkpendium.com!news.linkpendium.com!panix!usenet.stanford.edu!not-for-mail From: astian Newsgroups: gnu.bash.bug Subject: Re: backquote peculiarities Date: Tue, 16 Jul 2019 19:03:00 +0000 Lines: 60 Approved: bug-bash@gnu.org Message-ID: References: <8091.1563212947@jinx.noi.kre.to> <84005319-e232-8404-fe0b-471dafad381c@e-nautia.com> NNTP-Posting-Host: lists.gnu.org Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-Trace: usenet.stanford.edu 1563309668 13558 209.51.188.17 (16 Jul 2019 20:41:08 GMT) X-Complaints-To: action@cs.stanford.edu Cc: bug-bash@gnu.org To: chet.ramey@case.edu, Robert Elz Envelope-to: bug-bash@gnu.org DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=e-nautia.com; s=e-nautia; t=1563303849; bh=mPxWBgcKUpse5r/FeR3jttpTh9P34jtK2SBPqoXiI8A=; h=Subject:To:Cc:References:From:Date:In-Reply-To:From; b=MmfZXieprJf+XtQD98IsmT283Ac0yTsFKbhjhj0e6o+Q3L2lihNcLqVNZoo2NyAgG EysJrDr/vFwwiTtcJ33jYn9JfHrl5aOwpH1pOBzxDtxY7md4jCawDvMWBjgSPacePN 8Pn1NXPdRqRaZko3hfD/49xlFUmY40Ga9PFZYE2I= Authentication-Results: m1; dmarc=fail (p=none dis=none) header.from=e-nautia.com DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=e-nautia.com; s=e-nautia; t=1563303849; bh=mPxWBgcKUpse5r/FeR3jttpTh9P34jtK2SBPqoXiI8A=; h=Subject:To:Cc:References:From:Date:In-Reply-To:From; b=MmfZXieprJf+XtQD98IsmT283Ac0yTsFKbhjhj0e6o+Q3L2lihNcLqVNZoo2NyAgG EysJrDr/vFwwiTtcJ33jYn9JfHrl5aOwpH1pOBzxDtxY7md4jCawDvMWBjgSPacePN 8Pn1NXPdRqRaZko3hfD/49xlFUmY40Ga9PFZYE2I= In-Reply-To: Content-Language: en-US X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2001:41d0:303:7741::1 X-Mailman-Approved-At: Tue, 16 Jul 2019 16:41:08 -0400 X-BeenThere: bug-bash@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Bug reports for the GNU Bourne Again SHell List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Mailman-Original-Message-ID: X-Mailman-Original-References: <8091.1563212947@jinx.noi.kre.to> <84005319-e232-8404-fe0b-471dafad381c@e-nautia.com> Xref: csiph.com gnu.bash.bug:15182 Chet Ramey: > On 7/15/19 6:19 PM, astian wrote: > >>> I doubt it makes any difference to the timing, which I think >>> Chet has already answered, but it is worth pointing out that these >>> two commands ... >>> >>> printf '%s\n' "`printf %s "$i"`" >>> printf '%s\n' "$(printf %s "$i")" >>> >>> which (I believe)) are supposed to be the same thing, using the >>> different (ancient, and modern) forms of command substitution aren't >>> actually the same. In the first $i is unquoted, in the second it is >>> quoted. Here, since its value is just a number and IFS isn't being >>> fiddled, there is not likely to be any effect, but if you really >>> want to make those two the same, the first needs to be written as >>> >>> printf '%s\n' "`printf %s \"$i\"`" >>> >>> Such are the joys of `` command substitutions (just avoid them). >>> >>> kre >> >> Dear Robert Elz, I'm aware of several of its peculiarities and I typically do >> avoid them. However, is it true that $i is unquoted in the first case? > > POSIX makes it undefined behavior, and different shells do it differently. > Bash makes the $i quoted within the `` string, as you discovered. Ah, thanks for the clarification. I wonder if the excerpt below (particularly the last sentence) would be the relevant wording of POSIX, i.e. that some shells might interpret the command as the concatenation of a double-quoted string, the unquoted $i, and another double-quoted string: "`printf %s "$i"`" => CONCAT("`printf %s ", $i, "`") Which would then lead to "undefined results". Cheers. --- 2.2.3 Double-Quotes [0] Enclosing characters in double-quotes ( "" ) shall preserve the literal value of all characters within the double-quotes, with the exception of the characters backquote, , and , as follows: [...] ` The backquote shall retain its special meaning introducing the other form of command substitution (see Command Substitution). [...] Either of the following cases produces undefined results: - A single-quoted or double-quoted string that begins, but does not end, within the "`...`" sequence - A "`...`" sequence that begins, but does not end, within the same double-quoted string [...] 0: https://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html#tag_18_02_03