zsh-workers
 help / color / mirror / code / Atom feed
From: Mikael Magnusson <mikachu@gmail.com>
To: Zsh hackers list <zsh-workers@zsh.org>
Subject: Re: aliases in zsh -c and eval
Date: Thu, 27 Nov 2014 22:35:15 +0100	[thread overview]
Message-ID: <CAHYJk3Sawwany1qFiJ7jJsRdDUGdyJfarFiMGcY0U2caLbUFdA@mail.gmail.com> (raw)
In-Reply-To: <20141127212221.GC5951@chaz.gmail.com>

On Thu, Nov 27, 2014 at 10:22 PM, Stephane Chazelas
<stephane.chazelas@gmail.com> 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


  parent reply	other threads:[~2014-11-27 21:35 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-11-27 21:22 Stephane Chazelas
2014-11-27 21:25 ` Stephane Chazelas
2014-11-27 21:35 ` Mikael Magnusson [this message]
2014-11-27 21:35 ` Peter Stephenson

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CAHYJk3Sawwany1qFiJ7jJsRdDUGdyJfarFiMGcY0U2caLbUFdA@mail.gmail.com \
    --to=mikachu@gmail.com \
    --cc=zsh-workers@zsh.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).