Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: aliases in zsh -c and eval



2014-11-27 21:22:22 +0000, Stephane Chazelas:
> 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.
[...]

For completeness:

$ cat > a
alias foo=echo
foo bar
$ zsh a
bar
$ zsh -c '. ./a'
bar
$ zsh -c 'eval "$(cat ./a)"'
(eval):2: command not found: foo
$ ksh a
bar
$ ksh -c '. ./a'
ksh: .[2]: foo: not found [No such file or directory]

ksh worse this time.

-- 
Stephane



Messages sorted by: Reverse Date, Date, Thread, Author