From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 19974 invoked by alias); 27 Nov 2014 21:35:24 -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: 33812 Received: (qmail 16100 invoked from network); 27 Nov 2014 21:35:22 -0000 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-2.7 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,RCVD_IN_DNSWL_LOW autolearn=ham version=3.3.2 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type; bh=987ysqsVJ1Az2qy2gpTg2YaHEA4+6doLoKx3gzEo+uY=; b=PZLyBHc0Fx9RgPbur0kkKg2ubTmovJfu2GEIuLI+Lnct4D57SEr5NhDePJDMm16c5k xfxSowvbW9XP8kxkEi4rbktJjfJ7g41P71KzrkGQ4DxWIKZDlI6jE7AmRPKxE0+77S4o qz3rnVR82MmkqOKO7rPCqKg/vuKzNKZDPYPKH6XM2RefoMlhCW1qKs0iTzo+RKSWY/J1 iX4JXKXmtHF/6wyLtn2hmZJ2nIsFFPkQ/UFn7i8QW5DaZcCzbNYWCcOxG2gXqPo6WoVz NJIAKK2OFhIn3ctJrMUMS/lc5DeNGRW0j+Fp13lxsmzLfmuV3lGuMO4zzsoFZ6w0AtsK hZrA== MIME-Version: 1.0 X-Received: by 10.50.137.65 with SMTP id qg1mr29833418igb.37.1417124115763; Thu, 27 Nov 2014 13:35:15 -0800 (PST) In-Reply-To: <20141127212221.GC5951@chaz.gmail.com> References: <20141127212221.GC5951@chaz.gmail.com> Date: Thu, 27 Nov 2014 22:35:15 +0100 Message-ID: Subject: Re: aliases in zsh -c and eval From: Mikael Magnusson To: Zsh hackers list Content-Type: text/plain; charset=UTF-8 On Thu, Nov 27, 2014 at 10:22 PM, Stephane Chazelas wrote: > Hiya, > > it looks like aliases defined in `zsh -c` are not expanded in > there: > > $ zsh -c 'alias foo=echo > foo bar' > zsh:2: command not found: foo > > Those defined for instance in ~/.zshenv are expanded. And: > > $ zsh -c 'alias foo=echo > eval foo bar' > bar > > It looks like zsh is the only one out here. (with bash you need > bash -O expand_aliases). > > Same with eval: > > $ (eval 'alias foo=echo > subsh quote> foo bar') > zsh: command not found: foo > $ (eval 'alias foo=echo > eval foo bar') > bar > > This time, ksh93 does behave like zsh. > > -- > Stephane This is documented near the start of the "Aliasing" section of the manpage. There is a commonly encountered problem with aliases illustrated by the following code: alias echobar='echo bar'; echobar This prints a message that the command echobar could not be found. This happens because aliases are expanded when the code is read in; the entire line is read in one go, so that when echobar is executed it is too late to expand the newly defined alias. This is often a problem in shell scripts, functions, and code executed with `source' or `.'. Consequently, use of functions rather than aliases is recommended in non-interactive code. -- Mikael Magnusson