Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > gnu.bash.bug > #15609
| Path | csiph.com!weretis.net!feeder6.news.weretis.net!news.linkpendium.com!news.linkpendium.com!panix!usenet.stanford.edu!not-for-mail |
|---|---|
| From | Chet Ramey <chet.ramey@case.edu> |
| Newsgroups | gnu.bash.bug |
| Subject | Re: Issues with history substitution and its documentation |
| Date | Mon, 18 Nov 2019 14:55:47 -0500 |
| Lines | 85 |
| Approved | bug-bash@gnu.org |
| Message-ID | <mailman.1884.1574106955.13325.bug-bash@gnu.org> (permalink) |
| References | <CA+VKLw-WX8zUz06MZ9ThuMhUuW97aJ5ted8oSfJSvrVJBLW3hA@mail.gmail.com> <CA+VKLw_XMx1xjiFt-Tio8S+Mdt_AeS9v64SuMYYMdDdDnJFSBQ@mail.gmail.com> <CA+VKLw_hceb_xzu7kzTJAVuegWzqxJDa8xw4ja5TOBPpOWvRDQ@mail.gmail.com> <CA+VKLw_dh_SgozSCqqeg0SBTacx6PyobJff6Thu6uuV-LPCdeQ@mail.gmail.com> <CA+VKLw9c9B5FNg=48rE1v=mjZ-9Xnj9hyeyuJ0LcOYJZiMp=rQ@mail.gmail.com> <CA+VKLw_Npzqh2k8-6Uj3S7EYtXFj_TumBpqn=jsAJHPEXiWcxg@mail.gmail.com> <CA+VKLw-4D_2gyH8fwiB0cQSL0XjR0Ss+KqS2spD8FPKpFAyKhg@mail.gmail.com> <f94c53e3-fc6b-812a-6c12-493023b923c1@case.edu> |
| Reply-To | chet.ramey@case.edu |
| NNTP-Posting-Host | lists.gnu.org |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset=utf-8; format=flowed |
| Content-Transfer-Encoding | 8bit |
| X-Trace | usenet.stanford.edu 1574106956 25815 209.51.188.17 (18 Nov 2019 19:55:56 GMT) |
| X-Complaints-To | action@cs.stanford.edu |
| Cc | chet.ramey@case.edu |
| To | Jim Monte <jim.monte01@gmail.com>, bug-bash@gnu.org |
| Envelope-to | bug-bash@gnu.org |
| DKIM-Signature | v=1; a=rsa-sha256; c=relaxed/relaxed; d=case.edu; s=smtp-primary; t=1574106949; bh=1n1+cTSdkMTMDcoyjmyQ/bEXfUDcMv34y//AWJ/0Q+c=; h=Reply-To:Cc:Subject:To:References:From:Message-ID:Date: MIME-Version:In-Reply-To:Content-Type:Content-Transfer-Encoding; b=RrY5UZbCd2OOn/wztwsyf7IgTIq0OacLUmEU35oseuHqMdT8hPol3p9scyEBzIcrHv v2NiWlb3n4vjSMhyOHeeu8Xnv5o44Vjr6kxoTJyUBaIn4JUBTG4t8KWaZu+ZYiLGu8F wVbAL2AWCs9znSu1nHuLQsNL39eTHLh2HTSoQiM299L57+vB7BaldYQ4li/VsvVyHTt gSJZIfoq+PPE4EzD/J838lhnmeWCqYnLFZX2eCarlUL6shWpvIvkpl42dbrXYvY1kUg 3d+Hz4WK4G5KQtJ8UDW2HiY1kcSy+m5BAwXOVOke0nBhvpMfcRxIWfKJdr+oqf4Br2t E71IyZVg== |
| DKIM-Signature | v=1; a=rsa-sha256; c=relaxed/relaxed; d=case.edu; s=smtp-primary; t=1574106947; bh=DPWLUK0TPZmNsXP56sE1aMWxv2HqM8HwOsF5VdWhDIw=; h=Reply-To:Cc:Subject:To:References:From:Message-ID:Date: MIME-Version:In-Reply-To:Content-Type:Content-Transfer-Encoding; b=dX2P787I+3t/cbjUDDQSRUpvpwhso1VVIfrT52MUjhdNvFe8hLlnRMY7WvX/5XIzMs YAYCK/qstPd3MiCiFZaLQan2i1y2t4ztkwhHxV0KZNlpDVYJGB/+WGpgDbG+M6XmZGh h2ypkL8DqAEIT0ADmnUCQ5mAZ1pvivdmR7TMM3HTiAvJID7Csh9QvGTXShFgzRgiM4C pMDEcDMSWRrBG30N0QJinQvIw3Ob8A6Ye29YGnhHltwLEUKT4jN5UmWiWifvsE9qf2D V2YX9D0HAFM3lpmYXhfSfUOW64dlGdbgCnwHYSbLwSoAxOAepPjUBynlXElW9uGS05L mMXSbkQA== |
| User-Agent | Mozilla/5.0 (Macintosh; Intel Mac OS X 10.14; rv:68.0) Gecko/20100101 Thunderbird/68.2.2 |
| In-Reply-To | <CA+VKLw-4D_2gyH8fwiB0cQSL0XjR0Ss+KqS2spD8FPKpFAyKhg@mail.gmail.com> |
| Content-Language | en-US |
| X-Junkmail-Status | score=7/90, host=mpv4-2015.case.edu |
| X-Junkmail-PrAS-Raw | score=7/90, refid=2.7.2:2019.11.18.193916:17:7.944, ip=, rules=DKIM_SIGNATURE, __HAS_REPLYTO, __HAS_CC_HDR, __SUBJ_REPLY, __PHISH_SPEAR_SUBJ_ALERT, __BOUNCE_CHALLENGE_SUBJ, __BOUNCE_NDR_SUBJ_EXEMPT, __TO_MALFORMED_2, __TO_NAME, __TO_NAME_DIFF_FROM_ACC, __HAS_REFERENCES, __REFERENCES, __HAS_FROM, FROM_EDU_TLD, __HAS_MSGID, __SANE_MSGID, DATE_TZ_NA, __USER_AGENT, __MOZILLA_USER_AGENT, __MIME_VERSION, __IN_REP_TO, __CT, __CT_TEXT_PLAIN, __CTE, __REPLYTO_SAMEAS_FROM_ADDY, __REPLYTO_SAMEAS_FROM_ACC, __FROM_DOMAIN_IN_ANY_CC1, __FROM_DOMAIN_IN_ANY_CC2, __REPLYTO_SAMEAS_FROM_DOMAIN, __DKIM_ALIGNS_1, __DKIM_ALIGNS_2, __ANY_URI, __URI_MAILTO, __URI_WITH_PATH, __URI_NO_WWW, __HIGHBITS, __CP_URI_IN_BODY, __SUBJ_ALPHA_NEGATE, __URI_IN_BODY, __URI_NOT_IMG, __FORWARDED_MSG, __BODY_NO_MAILTO, __NO_HTML_TAG_RAW, BODY_SIZE_3000_3999, __MIME_TEXT_P1, __MIME_TEXT_ONLY, __URI_NS, HTML_00_01, HTML_00_10, DKIM_ALIGNS, [TRUNCATED], so=2010-03-03 19:42:08, dmn=2016-08-03-0138 |
| X-detected-operating-system | by eggs.gnu.org: GNU/Linux 2.4.x-2.6.x [generic] [fuzzy] |
| X-Received-From | 129.22.103.195 |
| 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 | <f94c53e3-fc6b-812a-6c12-493023b923c1@case.edu> |
| X-Mailman-Original-References | <CA+VKLw-WX8zUz06MZ9ThuMhUuW97aJ5ted8oSfJSvrVJBLW3hA@mail.gmail.com> <CA+VKLw_XMx1xjiFt-Tio8S+Mdt_AeS9v64SuMYYMdDdDnJFSBQ@mail.gmail.com> <CA+VKLw_hceb_xzu7kzTJAVuegWzqxJDa8xw4ja5TOBPpOWvRDQ@mail.gmail.com> <CA+VKLw_dh_SgozSCqqeg0SBTacx6PyobJff6Thu6uuV-LPCdeQ@mail.gmail.com> <CA+VKLw9c9B5FNg=48rE1v=mjZ-9Xnj9hyeyuJ0LcOYJZiMp=rQ@mail.gmail.com> <CA+VKLw_Npzqh2k8-6Uj3S7EYtXFj_TumBpqn=jsAJHPEXiWcxg@mail.gmail.com> <CA+VKLw-4D_2gyH8fwiB0cQSL0XjR0Ss+KqS2spD8FPKpFAyKhg@mail.gmail.com> |
| Xref | csiph.com gnu.bash.bug:15609 |
Show key headers only | View raw
On 11/6/19 10:21 AM, Jim Monte wrote: > Another documentation issue for :s, and a bug, or two bugs, although it > seems to be one of each. Instead of "Any delimiter may be used in place of > ‘/’.", it should be clarified that any character may be used in place of > '/' as a delimiter, although if '&' is used, it looses its special property > of being the value of old when it appears in new and if '\' is used, it > looses is ability to escape '&'. It doesn't. I think it would be clearer after an explanation of how the history expansion code parses substitutions and how backslashes act as escape characters during scanning. The principle to remember up front is that backslash can act as an escape character, but not in all contexts, and it is removed for the next stage of history expansion if it is used as an escape character. However, there is still an issue with an > escape being lost in some cases. > > [root@localhost ~]# echo a b c > a b c > [root@localhost ~]# echo "!:s&b&\\\&&&" > echo "echo a \& c&" ******************* one This is exactly what csh does. Here's why. The history code notes that the substitution delimiter is `&', so it has to scan forward for the separating and closing delimiters. The separating one after the lhs is easy. To find the closing delimiter, the backslash escapes one `&', the second `&' terminates the history substitution, and the third is held until later. The backslash escaping the `&' is removed. The backslash doesn't escape itself when scanning for the ending delimiter, so the replacement string is `\\&'. That replacement string gets post-processed for possible & interpolation, so it gets rescanned. During this rescanning, the backslash escapes only the `&', and not itself, so the backslash escapes the `&' and is removed. The final replacement string is '\&', and that gets substituted for `b' in the original event string. The final `&' doesn't participate in the history expansion, so it's just appended to the result. > [root@localhost ~]# echo a b c > a b c > [root@localhost ~]# echo "!:s/b/\\\&&/" > echo "echo a \\&b c" ******************* > echo a \&b c Right. You don't have to consume one backslash while scanning for the ending delimiter. > [root@localhost ~]# echo a b c > a b c > [root@localhost ~]# echo "!:szbz\\\&&z" > echo "echo a \\&b c" ******************* > echo a \&b c This is the same example. > [root@localhost ~]# echo a b c > a b c > [root@localhost ~]# echo "!:s\b\\\\&&\" > echo "echo a c\\&&\" >> " > echo a c\&&" > > [root@localhost ~]# echo a b c > a b c > [root@localhost ~]# echo "!:s\b\z\&&y\" > echo "echo a z c&&y\" >> " > echo a z c&&y" You should be able to work these out given the previous examples. Chet -- ``The lyf so short, the craft so long to lerne.'' - Chaucer ``Ars longa, vita brevis'' - Hippocrates Chet Ramey, UTech, CWRU chet@case.edu http://tiswww.cwru.edu/~chet/
Back to gnu.bash.bug | Previous | Next | Find similar | Unroll thread
Re: Issues with history substitution and its documentation Chet Ramey <chet.ramey@case.edu> - 2019-11-18 14:55 -0500
csiph-web