Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: aliases in zsh -c and eval
- X-seq: zsh-workers 33812
- From: Mikael Magnusson <mikachu@xxxxxxxxx>
- To: Zsh hackers list <zsh-workers@xxxxxxx>
- Subject: Re: aliases in zsh -c and eval
- Date: Thu, 27 Nov 2014 22:35:15 +0100
- 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==
- In-reply-to: <20141127212221.GC5951@chaz.gmail.com>
- List-help: <mailto:zsh-workers-help@zsh.org>
- List-id: Zsh Workers List <zsh-workers.zsh.org>
- List-post: <mailto:zsh-workers@zsh.org>
- Mailing-list: contact zsh-workers-help@xxxxxxx; run by ezmlm
- References: <20141127212221.GC5951@chaz.gmail.com>
On Thu, Nov 27, 2014 at 10:22 PM, Stephane Chazelas
<stephane.chazelas@xxxxxxxxx> 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
Messages sorted by:
Reverse Date,
Date,
Thread,
Author