From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 19363 invoked by alias); 17 Feb 2018 03:44:56 -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: List-Unsubscribe: X-Seq: 23133 Received: (qmail 19318 invoked by uid 1010); 17 Feb 2018 03:44:56 -0000 X-Qmail-Scanner-Diagnostics: from mta03.eastlink.ca 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(24.224.136.9):SA:0(-2.6/5.0):. Processed in 7.71736 secs); 17 Feb 2018 03:44:56 -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=-2.6 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_LOW, SPF_PASS,T_RP_MATCHES_RCVD autolearn=ham autolearn_force=no version=3.4.1 X-Envelope-From: rayandrews@eastlink.ca X-Qmail-Scanner-Mime-Attachments: | X-Qmail-Scanner-Zip-Files: | MIME-version: 1.0 Content-transfer-encoding: 8BIT Content-type: text/plain; charset=utf-8; format=flowed X-Authority-Analysis: v=2.3 cv=OKgJIxSB c=1 sm=1 tr=0 a=RnRVsdTsRxS/hkU0yKjOWA==:117 a=RnRVsdTsRxS/hkU0yKjOWA==:17 a=IkcTkHD0fZMA:10 a=jfziE6Ursyed8O2zpUYA:9 a=QEXdDO2ut3YA:10 X-EL-IP-NOAUTH: 24.207.101.9 Subject: Re: alias hygiene To: zsh-users@zsh.org References: <1679a1e0-f716-e501-c4c2-f7e485f9701f@eastlink.ca> <1518827410.2159479.1273706656.1F5B436D@webmail.messagingengine.com> From: Ray Andrews Message-id: <37bb7b6b-ad70-6d03-f979-0e0d3b0be4d3@eastlink.ca> Date: Fri, 16 Feb 2018 19:14:42 -0800 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.6.0 In-reply-to: <1518827410.2159479.1273706656.1F5B436D@webmail.messagingengine.com> Content-language: en-CA On 16/02/18 04:30 PM, Daniel Shahaf wrote: > > I don't understand your question, but allow me to review this code _without_ > knowing its context or purpose: Thanks Daniel, I did suspect it would not be kosher.  Is there some way to see how this looks to the parser after expansion?  That way I'd probably be able to understand the issue better. > > 0. It's a syntax error. > > 1. Calling the alias «_grep» clashes with compsys's function of that name. Ah!  So I could  just rename it as far as that goes?  It does seem to work fine, but this sounds like a gotcha. > > 2. Aliases don't have positional parameters. That «$1» is syntactically valid > but I am not sure whether it does what you want (or, rather, whether it would > do what you want after you fix #4). Actually that's the reason for the alias, I want it to pick up the parameters inline after the alias is expanded.   It does what I want but I question its safety.  In practical terms the "^|$string|$second_string"   construction is not something I want to try passing to a function so I thought to just leave it there for the expanded alias to eat, that is, for egrep to eat.  So I guess I'm being a bit chicken not using a function. > > 3. Do not interpolate strings into command strings; that's a bobby tables bug. This is what I had expected the issue would be.  Mind, I cobble strings together into command strings all the time and I've gotten used to the little tweaks needed.  How can I read up on this 'bobby tables'?  I might have developed some bad habits. > > 4. Those pipe characters are not quoted so they create a pipeline, which you > did not intend. It would appear that you have not tested that codepath. I suspect the context would show that all right, I do end up with my pipes working ok.  It's rather convoluted, sorry if the snip was not satisfactory, I was essentially worried about the conditional alias being a good idea from the getgo, not about the subsequent details which are not complete.  I don't think I've ever seen a conditional alias before. > > More information: > > 0. «||» is invalid at the start of a logical line. Either there is an error > message you did not tell us about or there is a difference between what you ran > and what you posted. Right, context again, I should only show what is strictly relevant to the question. > > 1. That matters because aliases and functions are both invoked by entering their > name in command position. It's possible this doesn't have any effect (depends > on how you autoload compinit) but it's still a bug. > > 2. «$1» would be fine in specific circumstances, but it's usually a mistake. If > that code is in zshrc toplevel then the use of «$1» is definitely a mistake. > > 3. «alias foo='egrep --color=always -- ${(q)string}'» would be better (although > I do not vouch that that --color=always switch is correct in the wider context). > In other contexts arrays can be used (but not here). Thanks, I forget about ' (q) '. > > 4. The command string «print -lr "foo "bar baz" qux"» has four words: «print», «-lr», > «foo bar», and «baz qux». >