zsh-workers
 help / color / mirror / code / Atom feed
From: Peter Stephenson <p.w.stephenson@ntlworld.com>
To: Zsh hackers list <zsh-workers@zsh.org>
Subject: Re: aliases in zsh -c and eval
Date: Thu, 27 Nov 2014 21:35:47 +0000	[thread overview]
Message-ID: <20141127213547.27212718@pws-pc.ntlworld.com> (raw)
In-Reply-To: <20141127212221.GC5951@chaz.gmail.com>

On Thu, 27 Nov 2014 21:22:22 +0000
Stephane Chazelas <stephane.chazelas@gmail.com> wrote:
> 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

Yes, this is normal in text which is input in one go, as documented in
"Aliasing" in the grammar section of the manual, see below.  This is
inevitable as the whole thing is passed to the shell as a single string,
so it's input as a single string.  Presumably some other shells have
input factored in such a way that strings and files are considered more
similarly.


There is a commonly encountered problem with aliases
illustrated by the following code:

example(alias echobar='echo bar'; echobar)

This prints a message that the command tt(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 tt(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 `tt(source)'
or `tt(.)'.  Consequently, use of functions rather than aliases is
recommended in non-interactive code.

pws


      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
2014-11-27 21:35 ` Peter Stephenson [this message]

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=20141127213547.27212718@pws-pc.ntlworld.com \
    --to=p.w.stephenson@ntlworld.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).