From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 25482 invoked by alias); 10 Sep 2017 20:06:45 -0000 Mailing-List: contact zsh-workers-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Workers List List-Post: List-Help: X-Seq: 41663 Received: (qmail 5853 invoked by uid 1010); 10 Sep 2017 20:06:45 -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.143977 secs); 10 Sep 2017 20:06:45 -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=IkcTkHD0fZMA:10 a=x7bEGLp0ZPQA:10 a=pGLkceISAAAA:8 a=4drzY_Dv_sMpaCfiUTcA:9 a=QEXdDO2ut3YA:10 a=6kGIvZw6iX1k4Y-7sg4_:22 Date: Sun, 10 Sep 2017 21:06:36 +0100 From: Peter Stephenson To: zsh-workers@zsh.org Subject: Re: Comment (# char) behavior in the sub-shell Message-ID: <20170910210636.17bc0581@ntlworld.com> In-Reply-To: References: 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=UTF-8 Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ntlworld.com; s=meg.feb2017; t=1505073997; bh=ugiLOcYYJx3DEsh4YmqRQqRrW0V8w4D0ibzI9VbaNBk=; h=Date:From:To:Subject:In-Reply-To:References; b=iv9alNvP5II0Mrtzn3/Jduf1PINqdJGOZjPTtxvUaTGQfB1Sc35Vegx/HDzYabFYv VPVKZwyPeaE5gRdHIss7+4ZwKLXTw+4dyRL2Swkj6rsY9kYXx7FT51oYESKc1v9pCC JhJKtvg3ekfef7pKx4FXHIzd26NrH77b2+p8qUwIGdE9KLHlzgGZqIL1u33WZIl1RD R8LCEv5TrpEvTg1KQUed+GPiBsIk3AlnX0uQyYDeQWYifBHUUdmerHFRO4Fc3bdRkh viQIELQoKceHhuv9oGv2upV8pPEBZuq0PrWO9m10go+XRh+DCgx3OrLIEMEs6HGj90 PJ8sV8HqhU43Q== On Sat, 9 Sep 2017 19:33:59 +0300 Stanislav Seletskiy wrote: > zsh version: 5.4.2 >=20 > I'm heavy user of `#`-aliases, so I like to do stuff like `seq 1 10 # > 9` to grep for `9` (`alias -g -- '#'=3D'| grep'`). >=20 > It works as expected when I'm entering command in interactive mode > without sub-shell, like: >=20 > `$ seq 1 10 # 9` =E2=80=94 works well, I see only `9` in the output. >=20 > But when I'm trying to use same alias in the sub-shell (e.g. inside > `$()`), it doesn't work anymore: >=20 > `$ echo $(seq 1 10 # 9)` =E2=80=94 doesn't work, I see `1 2 3 ... 10` in = the output. I suspect this changed some versions ago now. At some point we changed the way we handled $(...) to parse it better. Previously, we just blindly treated it as a string when we first enountered it, reading it in interactively until we got to a closing parenthesis. That wasn't actually the right thing to do, and crucially it failed where there was a case statement in the old syntax where a pattern only has a closing parenthesis and not an opening parenthesis. So what we do now is parse properly until the (right) closing parenthesis, but still store what we parsed as a string for reading again when we execute the $(...). It so happens we don't keep the expanded aliases from the original parse in the string we later replay. There is a test for just this case; here it is: alias fooalias=3Dbarexpansion funcwithalias() { echo $(fooalias); } functions funcwithalias barexpansion() { print This is the correct output.; } funcwithalias 0:Alias expanded in command substitution does not appear expanded in text >funcwithalias () { > echo $(fooalias) >} >This is the correct output. You'll see that the output from "functions" shown at the end contains the unexpanded alias (that "0:..." in the middle simply gives the expected exit status for the code above and a description). In your case, that would be the "#", and at the point where it finally does get read in, in recent shell versions, it's treated like a string, not interactive input. If we kept expanded aliases the definition of functionwithalias would change correspondingly. Actually, there is an argument for that since since that's what would happen for an alias in the main body of the function, but I'm not sure how close the parallels are I'm not sure how much effort this is worth. pws