From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 12221 invoked by alias); 10 Sep 2017 18:58:06 -0000 Mailing-List: contact zsh-users-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Users List List-Post: List-Help: X-Seq: 22888 Received: (qmail 23869 invoked by uid 1010); 10 Sep 2017 18:58:06 -0000 X-Qmail-Scanner-Diagnostics: from know-smtprelay-omc-9.server.virginmedia.net by f.primenet.com.au (envelope-from , uid 7791) with qmail-scanner-2.11 (clamdscan: 0.99.2/21882. spamassassin: 3.4.1. Clear:RC:0(80.0.253.73):SA:0(-4.7/5.0):. Processed in 2.325943 secs); 10 Sep 2017 18:58:06 -0000 X-Spam-Checker-Version: SpamAssassin 3.4.1 (2015-04-28) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-4.7 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,SPF_PASS,T_DKIM_INVALID autolearn=ham autolearn_force=no version=3.4.1 X-Envelope-From: p.w.stephenson@ntlworld.com X-Qmail-Scanner-Mime-Attachments: | X-Qmail-Scanner-Zip-Files: | X-Originating-IP: [86.21.219.59] X-Authenticated-User: p.w.stephenson@ntlworld.com X-Spam: 0 X-Authority: v=2.1 cv=aJkN0uJm c=1 sm=1 tr=0 a=utowdAHh8RITBM/6U1BPxA==:117 a=utowdAHh8RITBM/6U1BPxA==:17 a=L9H7d07YOLsA:10 a=9cW_t1CCXrUA:10 a=s5jvgZ67dGcA:10 a=kj9zAlcOel0A:10 a=x7bEGLp0ZPQA:10 a=jKjxfLc-AAAA:8 a=DgJx_bYRipNQ_tIdBI0A:9 a=CjuIK1q_8ugA:10 Date: Sun, 10 Sep 2017 19:57:58 +0100 From: Peter Stephenson To: zsh-users@zsh.org Subject: Re: string overwrites string when echoed Message-ID: <20170910195758.13290f1b@ntlworld.com> In-Reply-To: <86o9qimn03.fsf@zoho.com> References: <86o9qkqbes.fsf@zoho.com> <170909100149.ZM8451@torch.brasslantern.com> <86shfumrzm.fsf@zoho.com> <20170910175943.77a8313a@ntlworld.com> <86o9qimn03.fsf@zoho.com> X-Mailer: Claws Mail 3.11.1 (GTK+ 2.24.28; x86_64-redhat-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ntlworld.com; s=meg.feb2017; t=1505069879; bh=n+HX7plXg7CzVLF3UptiaQXm5YY5lOk7gEaP+Uv68Js=; h=Date:From:To:Subject:In-Reply-To:References; b=XSibnx/NoZjRRb4hbNOCD2yGhmCpPEIctqPhY4NGk+gY3AbI+0OQx7hGYJ6VcaYZ0 d5koRPpKS1M1hXV5McAdnKghmJdbhFYEaurb+jTyk99VbTwpa/NkRTQgokXWAjIo7J JZyqjyCVXnEyY5sfKVYux+SCY3k8X3KSK94IBNmhU2prfJHIE4QihsP+8xbg4c0bcK z+BrZvUR84aQcoVixC5lTO4WiA39KonaxWF68LVc2T3z/GJixrRzc32hg3W0ySEj/c Mn4DKP0295TTs7BP9qURt97z0Omqe2dBzGDUVR/ZeHs41aJJvVsbkVIXYH2YGBz/U/ 1X9ma81wcgcew== On Sun, 10 Sep 2017 20:23:08 +0200 Emanuel Berg wrote: > Feel free to elaborate on ${reply%%$'\r'}. > What does it do? Remove the last char of the > string if it matches the char given? %% is a standard pattern match operator (works in most shells) that removes the longest possible match of the following pattern. % is similar but removes the shortest possible match: I used %% because they do the same thing in this case (it's a single fixed character) and I happen to know the longest match is generally more efficient to evaluate. This is documented in the PARAMETER EXPANSION section of the zshexpn manual. $'...' is an increasingly common form of quoting that allows escape sequences like the print builtin, so $'\r' exands to a carriage return. This is documented in the section QUOTING in the zshmisc manual page (except it doesn't say much more than what I did before you have to go away and read the entry for the print builtin). pws