From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 23848 invoked by alias); 17 Feb 2018 00:39:22 -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: 23132 Received: (qmail 2052 invoked by uid 1010); 17 Feb 2018 00:39:22 -0000 X-Qmail-Scanner-Diagnostics: from out5-smtp.messagingengine.com 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(66.111.4.29):SA:0(-2.6/5.0):. Processed in 0.616829 secs); 17 Feb 2018 00:39:22 -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, T_DKIM_INVALID autolearn=ham autolearn_force=no version=3.4.1 X-Envelope-From: d.s@daniel.shahaf.name X-Qmail-Scanner-Mime-Attachments: | X-Qmail-Scanner-Zip-Files: | DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= daniel.shahaf.name; h=content-transfer-encoding:content-type :date:from:in-reply-to:message-id:mime-version:references :subject:to:x-me-sender:x-me-sender:x-sasl-enc; s=fm2; bh=Cj6+7o mF2/CcXNTw6C4Tlzk+5PtPoaA+gAoUcTD/dko=; b=OgvFI/2S/Z7CNhR5NHikg8 kB672fo50rKnjgzfb37E72CV9ysi6GmdsUf110iEkdMQLUirIztqQIIW0R16Po3Q guLFHQ9Zslz5SM+itETT1bvnAJmrlbNfmzCriRl8vvvKhBP57no9dX9DO5m8AgZ1 onau3eO0NjnSUoT8SxTtNYRY5ze7H14hBSo4qFY8seZmYFZBpyA5YnEpubYNbB+2 eE5GdBvyJ1wCOrTZnvr8pDNfHOnzlCUW28HrI6obWuMt/xzSyNB5R03EKRdGtyDc hGT/aC2mQRYvIKAabMO0GxT2qsGP9Tph2MVzatQ/DfwNu7YLymQQNnbDouw8xSUw == DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=content-transfer-encoding:content-type :date:from:in-reply-to:message-id:mime-version:references :subject:to:x-me-sender:x-me-sender:x-sasl-enc; s=fm2; bh=Cj6+7o mF2/CcXNTw6C4Tlzk+5PtPoaA+gAoUcTD/dko=; b=drfYKSmEMVhiT3ypxBAeDP NRjov/T4r2A/3QsXpyRNgN1adzHRU5ioT9Mc42WCrhenqBRh55KKlWz7POY87H9y WzIsJc6WrkwbKEdolEyaoflM9m4S5UkYqb2EMZDpAHDsNcPd+9MOY2H9KJkUk4sf Te49UJtvs1dTagAzEg4AwtE7yREXgQDsndPMkFJljOwc00eG4A/Hqv8utLn1EpJZ HhwpGI9C9HqztJooQW8pKaUTgMks7zIiUY34LXmOJvS5yFu4ds/TgDuHwPBxGnF8 giLLPpOXxS8qcKDM6VXhNQ9tNiS1Wy0ndattma+xILp5w0+zBBLfgox4s7dTapmQ == X-ME-Sender: Message-Id: <1518827410.2159479.1273706656.1F5B436D@webmail.messagingengine.com> From: Daniel Shahaf To: zsh-users@zsh.org MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" X-Mailer: MessagingEngine.com Webmail Interface - ajax-1b99b2df In-Reply-To: <1679a1e0-f716-e501-c4c2-f7e485f9701f@eastlink.ca> Date: Sat, 17 Feb 2018 00:30:10 +0000 Subject: Re: alias hygiene References: <1679a1e0-f716-e501-c4c2-f7e485f9701f@eastlink.ca> Ray Andrews wrote on Wed, 14 Feb 2018 08:09 -0800: >=20 > [ some test ] && alias _grep=3D"egrep --color=3Dalways "$string"" > || alias _grep=3D"egrep --color=3Dalways "^|= $1|$string"" >=20 > ... the alias will end up downstream from a pipe which is why there's no= =20 > filespec. >=20 > Is that sort of thing sanitary? I don't understand your question, but allow me to review this code _without_ knowing its context or purpose: 0. It's a syntax error. 1. Calling the alias =C2=AB_grep=C2=BB clashes with compsys's function of t= hat name. 2. Aliases don't have positional parameters. That =C2=AB$1=C2=BB is syntac= tically valid but I am not sure whether it does what you want (or, rather, whether it wou= ld do what you want after you fix #4). 3. Do not interpolate strings into command strings; that's a bobby tables b= ug. 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. More information: 0. =C2=AB||=C2=BB 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. 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 (depe= nds on how you autoload compinit) but it's still a bug. 2. =C2=AB$1=C2=BB would be fine in specific circumstances, but it's usually= a mistake. If that code is in zshrc toplevel then the use of =C2=AB$1=C2=BB is definitely= a mistake. 3. =C2=ABalias foo=3D'egrep --color=3Dalways -- ${(q)string}'=C2=BB would b= e better (although I do not vouch that that --color=3Dalways switch is correct in the wider co= ntext). In other contexts arrays can be used (but not here). 4. The command string =C2=ABprint -lr "foo "bar baz" qux"=C2=BB has four wo= rds: =C2=ABprint=C2=BB, =C2=AB-lr=C2=BB, =C2=ABfoo bar=C2=BB, and =C2=ABbaz qux=C2=BB.