zsh-users
 help / color / mirror / code / Atom feed
* strange alias effects
@ 2000-05-29  9:56 Andy Spiegl
  2000-05-29 10:13 ` Bart Schaefer
  2000-05-29 11:44 ` Andrej Borsenkow
  0 siblings, 2 replies; 12+ messages in thread
From: Andy Spiegl @ 2000-05-29  9:56 UTC (permalink / raw)
  To: ZSH User List

I just upgraded to 3.1.7-pre-4 and found something strange:

In my dot-files I've got this (among others):
 alias psl='ps -eo user,pid,ppid,cpu,pmem,rss,vsize,bsdtime,bsdstart,cmd --sort user,pid | \grep -v "bsdtime,bsdstart"' 
 alias pslS='ps -eo user,pid,ppid,cpu,pmem,rss,vsize,bsdtime,bsdstart,cmd --sort -size | \grep -v "bsdtime,bsdstart"'
 look.for () { psl | \grep -iE "(^USER|$@)" | \grep -v "grep -iE" }
 alias lookall='psl | grep -vE "(^($USERNAME|root|bin))|login"'

When I type
 look.for ssh-agent
I get:
 look.for: command not found: psl

"lookall" works as usual.

After typing
 look.for () { psl | \grep -iE "(^USER|$@)" | \grep -v "grep -iE" }
on the shell prompt, it works.

Can anyone explain this to me, please?
 Thanks,
   Andy.

-- 
 E-Mail: Andy@spiegl.de     URL: http://andy.spiegl.de
 PGP/GPG: see headers
                                o      _     _         _
  --------- __o       __o      /\_   _ \\o  (_)\__/o  (_)
  ------- _`\<,_    _`\<,_    _>(_) (_)/<_    \_| \   _|/' \/
  ------ (_)/ (_)  (_)/ (_)  (_)        (_)   (_)    (_)'  _\o_
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: strange alias effects
  2000-05-29  9:56 strange alias effects Andy Spiegl
@ 2000-05-29 10:13 ` Bart Schaefer
  2000-05-29 10:27   ` Andy Spiegl
  2000-05-29 11:44 ` Andrej Borsenkow
  1 sibling, 1 reply; 12+ messages in thread
From: Bart Schaefer @ 2000-05-29 10:13 UTC (permalink / raw)
  To: Andy Spiegl, ZSH User List

On May 29, 11:56am, Andy Spiegl wrote:
} Subject: strange alias effects
}
} Can anyone explain this to me, please?

Did you happen to compile your dot-files with zcompile?

As previously discussed, aliases and compilation don't play well together
because compilation records the lexical tokens as of the instant of
compilation and bypasses alias expansion at time of execution.  It's the
same problem as "Bart Schaefer's rule" in FAQ 2.3, except that the entire
zcompile'd file behaves as if it were one giant function definition.

Even if that's not your problem, it probably deserves a FAQ mention.

-- 
Bart Schaefer                                 Brass Lantern Enterprises
http://www.well.com/user/barts              http://www.brasslantern.com

Zsh: http://www.zsh.org | PHPerl Project: http://phperl.sourceforge.net   


^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: strange alias effects
  2000-05-29 10:13 ` Bart Schaefer
@ 2000-05-29 10:27   ` Andy Spiegl
  2000-05-29 13:32     ` Sven Wischnowsky
  0 siblings, 1 reply; 12+ messages in thread
From: Andy Spiegl @ 2000-05-29 10:27 UTC (permalink / raw)
  To: ZSH User List

Bart Schaefer wrote,

> Did you happen to compile your dot-files with zcompile?
No, never used that.
And the same dot-files worked perfectly with 3.1.6.pws21.

> It's the same problem as "Bart Schaefer's rule" in FAQ 2.3

Are you talking about this one?
> 4) If you have aliases that refer to each other (alias ls "ls -C";
>    alias lf "ls -F" ==> lf == ls -C -F) then you must either:
>
>       o  convert all of them to zsh functions; or
>       o  after converting, be sure your .zshrc defines all of your
>          aliases before it defines any of your functions.

Do I really have to separate aliases and functions?
I'd hate to do that, because I've got them nicely sorted by subjects in my
.zsh/alias.  :-(

Thanks,
 Andy.

-- 
 E-Mail: Andy@spiegl.de     URL: http://andy.spiegl.de
 PGP/GPG: see headers
                                o      _     _         _
  --------- __o       __o      /\_   _ \\o  (_)\__/o  (_)
  ------- _`\<,_    _`\<,_    _>(_) (_)/<_    \_| \   _|/' \/
  ------ (_)/ (_)  (_)/ (_)  (_)        (_)   (_)    (_)'  _\o_
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 Love, not time, heals all wounds.


^ permalink raw reply	[flat|nested] 12+ messages in thread

* RE: strange alias effects
  2000-05-29  9:56 strange alias effects Andy Spiegl
  2000-05-29 10:13 ` Bart Schaefer
@ 2000-05-29 11:44 ` Andrej Borsenkow
  2000-05-29 12:06   ` Andrej Borsenkow
  1 sibling, 1 reply; 12+ messages in thread
From: Andrej Borsenkow @ 2000-05-29 11:44 UTC (permalink / raw)
  To: Andy Spiegl, ZSH User List

> In my dot-files I've got this (among others):
>  alias psl='ps -eo
> user,pid,ppid,cpu,pmem,rss,vsize,bsdtime,bsdstart,cmd --sort
> user,pid | \grep -v "bsdtime,bsdstart"'
>  alias pslS='ps -eo
> user,pid,ppid,cpu,pmem,rss,vsize,bsdtime,bsdstart,cmd --sort
> -size | \grep -v "bsdtime,bsdstart"'
>  look.for () { psl | \grep -iE "(^USER|$@)" | \grep -v "grep -iE" }
>  alias lookall='psl | grep -vE "(^($USERNAME|root|bin))|login"'
>
> When I type
>  look.for ssh-agent
> I get:
>  look.for: command not found: psl
>
> "lookall" works as usual.
>

This trick works for me:

bor@itsrm2% cat ~/.zsh.d/functions/bar
foo
bor@itsrm2% alias foo='echo xxx'
bor@itsrm2% autoload bar
bor@itsrm2% bar
xxx

Note, that this works irrespectively of alias/autoload order.

I actually think, that autoloading functions provides more clean way
than definig them directly in dot-files.


> After typing
>  look.for () { psl | \grep -iE "(^USER|$@)" | \grep -v "grep -iE" }
> on the shell prompt, it works.
>
> Can anyone explain this to me, please?

Well, aliases are not expanded in direct function defiition (correct me,
Bart). Weirdly enough, they are expanded (by default) in autoloaded
functions.

-andrej


^ permalink raw reply	[flat|nested] 12+ messages in thread

* RE: strange alias effects
  2000-05-29 11:44 ` Andrej Borsenkow
@ 2000-05-29 12:06   ` Andrej Borsenkow
  2000-05-29 12:13     ` Andy Spiegl
  0 siblings, 1 reply; 12+ messages in thread
From: Andrej Borsenkow @ 2000-05-29 12:06 UTC (permalink / raw)
  To: Andy Spiegl, ZSH User List

>
> Well, aliases are not expanded in direct function defiition
> (correct me,
> Bart). Weirdly enough, they are expanded (by default) in autoloaded
> functions.
>


Sorry, this is of course wrong. You just seem to have alias definition
*after* function definition. Because aliases are expanded when function
is *defined*, they are not seen when functnio is executed.

Autoloading provides neat workaround - function body is first read in
after everything else  (including aliases) was already defined. For the
same reason, second function definition in your example (on command
line) works as expected - aliases are already known.

-andrej


^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: strange alias effects
  2000-05-29 12:06   ` Andrej Borsenkow
@ 2000-05-29 12:13     ` Andy Spiegl
  2000-05-29 12:30       ` Andrej Borsenkow
  0 siblings, 1 reply; 12+ messages in thread
From: Andy Spiegl @ 2000-05-29 12:13 UTC (permalink / raw)
  To: ZSH User List

> Sorry, this is of course wrong. You just seem to have alias definition
> *after* function definition. Because aliases are expanded when function
> is *defined*, they are not seen when functnio is executed.
That would make sense to me, but I _do_ have the alias defined before the
function.  And since this was no problem until I upgraded to 3.1.7-pre-4
I suspect I found a tiny bug???

> Autoloading provides neat workaround - function body is first read in
> after everything else  (including aliases) was already defined. For the
> same reason, second function definition in your example (on command
> line) works as expected - aliases are already known.
Hm, this sounds like a solution, but I'd hate to do that, because I've got
them all nicely sorted by subject in my .zsh/alias.  :-(

Thanks,
 Andy.

PS: cc to me is not necessary.  I am usually subscribed to the lists
    I post to. :-)

-- 
 E-Mail: Andy@spiegl.de     URL: http://andy.spiegl.de
 PGP/GPG: see headers
                                o      _     _         _
  --------- __o       __o      /\_   _ \\o  (_)\__/o  (_)
  ------- _`\<,_    _`\<,_    _>(_) (_)/<_    \_| \   _|/' \/
  ------ (_)/ (_)  (_)/ (_)  (_)        (_)   (_)    (_)'  _\o_
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 "There are two things that are infinite; Human stupidity and the
 universe. And I'm not sure about the universe." - Albert Einstein


^ permalink raw reply	[flat|nested] 12+ messages in thread

* RE: strange alias effects
  2000-05-29 12:13     ` Andy Spiegl
@ 2000-05-29 12:30       ` Andrej Borsenkow
  2000-05-29 12:59         ` Andy Spiegl
  0 siblings, 1 reply; 12+ messages in thread
From: Andrej Borsenkow @ 2000-05-29 12:30 UTC (permalink / raw)
  To: ZSH User List

>
> > Sorry, this is of course wrong. You just seem to have alias
> definition
> > *after* function definition. Because aliases are expanded
> when function
> > is *defined*, they are not seen when functnio is executed.
> That would make sense to me, but I _do_ have the alias
> defined before the
> function.  And since this was no problem until I upgraded to
> 3.1.7-pre-4
> I suspect I found a tiny bug???
>

I cannot reproduce it. I tried to add the same lines

alias foo='echo xxx'
bar() { foo }

to both ~/.zshenv and ~/.zshrc. In both cases it works as expected.
Sourcing file with the above defintions from .zshrc works as well. This
is with current CVS version.

>
> PS: cc to me is not necessary.  I am usually subscribed to the lists
>     I post to. :-)
>

Well, unfortunately, to be able to reply to list I have to use "Reply to
all" ... and manually removing recipients every time ...

It is exactly the reason I have procmail recipe that removes duplicates
;-0

-andrej


^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: strange alias effects
  2000-05-29 12:30       ` Andrej Borsenkow
@ 2000-05-29 12:59         ` Andy Spiegl
       [not found]           ` <000301bfc96e$cf7af2b0$21c9ca95@mow.siemens.ru>
  0 siblings, 1 reply; 12+ messages in thread
From: Andy Spiegl @ 2000-05-29 12:59 UTC (permalink / raw)
  To: ZSH User List

> > That would make sense to me, but I _do_ have the alias defined before
> > the function.  And since this was no problem until I upgraded to
> > 3.1.7-pre-4 I suspect I found a tiny bug???

> I cannot reproduce it. I tried to add the same lines
> 
> alias foo='echo xxx'
> bar() { foo }
These lines work for me, too.
But they probably have to, as the FAQ says:
   be sure your .zshrc defines all of your
   aliases before it defines any of your functions.

So the problem probably starts when there are more aliases after the
definition of bar.  I'll attach my (lengthy) .zsh/alias file.  Please try it.

> Well, unfortunately, to be able to reply to list I have to use "Reply to
> all" ... and manually removing recipients every time ...
> 
> It is exactly the reason I have procmail recipe that removes duplicates
> ;-0
That's one solution.  Using mutt is another. :-)

Thanks,
 Andy.

-- 
 E-Mail: Andy@spiegl.de     URL: http://andy.spiegl.de
 PGP/GPG: see headers
                                o      _     _         _
  --------- __o       __o      /\_   _ \\o  (_)\__/o  (_)
  ------- _`\<,_    _`\<,_    _>(_) (_)/<_    \_| \   _|/' \/
  ------ (_)/ (_)  (_)/ (_)  (_)        (_)   (_)    (_)'  _\o_
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 "security is an exercise in applied paranoia"       -- Unknown


^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: strange alias effects
       [not found]           ` <000301bfc96e$cf7af2b0$21c9ca95@mow.siemens.ru>
@ 2000-05-29 13:13             ` Andy Spiegl
  0 siblings, 0 replies; 12+ messages in thread
From: Andy Spiegl @ 2000-05-29 13:13 UTC (permalink / raw)
  To: ZSH User List

[-- Attachment #1: Type: text/plain, Size: 737 bytes --]

> > So the problem probably starts when there are more aliases after the
> > definition of bar.  I'll attach my (lengthy) .zsh/alias file. 
> >  Please try it.
> 
> I have not got any.
Ooops.

> > That's one solution.  Using mutt is another. :-)
> 
> Does it always skip attachements? :-))))
The program can only be as smart as its user. :-)

Andy.

-- 
 E-Mail: Andy@spiegl.de     URL: http://andy.spiegl.de
 PGP/GPG: see headers
                                o      _     _         _
  --------- __o       __o      /\_   _ \\o  (_)\__/o  (_)
  ------- _`\<,_    _`\<,_    _>(_) (_)/<_    \_| \   _|/' \/
  ------ (_)/ (_)  (_)/ (_)  (_)        (_)   (_)    (_)'  _\o_
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

[-- Attachment #2: alias.gz --]
[-- Type: application/x-gzip, Size: 7331 bytes --]

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: strange alias effects
@ 2000-05-29 13:32     ` Sven Wischnowsky
  2000-05-29 13:47       ` Andy Spiegl
  2000-05-29 17:24       ` Bart Schaefer
  0 siblings, 2 replies; 12+ messages in thread
From: Sven Wischnowsky @ 2000-05-29 13:32 UTC (permalink / raw)
  To: zsh-users


Andy Spiegl wrote:

> I just upgraded to 3.1.7-pre-4 and found something strange:
> 
> In my dot-files I've got this (among others):
>  alias psl='ps -eo user,pid,ppid,cpu,pmem,rss,vsize,bsdtime,bsdstart,cmd --sort user,pid | \grep -v "bsdtime,bsdstart"' 
>  alias pslS='ps -eo user,pid,ppid,cpu,pmem,rss,vsize,bsdtime,bsdstart,cmd --sort -size | \grep -v "bsdtime,bsdstart"'
>  look.for () { psl | \grep -iE "(^USER|$@)" | \grep -v "grep -iE" }
>  alias lookall='psl | grep -vE "(^($USERNAME|root|bin))|login"'
> 
> When I type
>  look.for ssh-agent
> I get:
>  look.for: command not found: psl
> 
> "lookall" works as usual.
> 
> After typing
>  look.for () { psl | \grep -iE "(^USER|$@)" | \grep -v "grep -iE" }
> on the shell prompt, it works.

I doubt that this worked before. Maybe you just didn't use it for some 
time and changed your file in the meantime? Adding that `if', for example?

It was always the case that syntactical constructs like if/the/else
and loops were parsed completely. So if you do:

  if [ -z ${OSTYPE:#solaris*} ]; then
    alias psl='ps -eo user,pid,ppid,pri,pcpu,vsz,pmem,stime,time,args | sort +1n -2 | \grep -v "stime,time"'
    alias pslS='ps -eo user,pid,ppid,pri,pcpu,vsz,pmem,stime,time,args | sort -k 6,6n | \grep -v "stime,time"'
    look () { psl | head -1; psl | \egrep -i $@ | \grep -v egrep }
    alias lookall='psl | \egrep -v "($USER|root|bin)"'
  else
    ...
  fi

the whole thing is parsed at once. When it is executed, the alias is
defined, but in this case the functions are already parsed, too. If
the aliases were before the `if' or if you would split the whole thing 
in two:

  if [ -z ${OSTYPE:#solaris*} ]; then
    alias psl='ps -eo user,pid,ppid,pri,pcpu,vsz,pmem,stime,time,args | sort +1n -2 | \grep -v "stime,time"'
    alias pslS='ps -eo user,pid,ppid,pri,pcpu,vsz,pmem,stime,time,args | sort -k 6,6n | \grep -v "stime,time"'
    alias lookall='psl | \egrep -v "($USER|root|bin)"'
  else
    ...
  fi
  if [ -z ${OSTYPE:#solaris*} ]; then
    look () { psl | head -1; psl | \egrep -i $@ | \grep -v egrep }
  else
    ...
  fi

it'll work, because then the shell gets the first if/then/else,
executes it and then calls the parser to get the second one.

It isn't special to zsh, either. All shells (have to) behave this way.


Bye
 Sven

P.S.: [[..]] is faster than [..].

--
Sven Wischnowsky                         wischnow@informatik.hu-berlin.de


^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: strange alias effects
  2000-05-29 13:32     ` Sven Wischnowsky
@ 2000-05-29 13:47       ` Andy Spiegl
  2000-05-29 17:24       ` Bart Schaefer
  1 sibling, 0 replies; 12+ messages in thread
From: Andy Spiegl @ 2000-05-29 13:47 UTC (permalink / raw)
  To: ZSH User List

Andrej and Sven,

> I doubt that this worked before. Maybe you just didn't use it for some 
> time and changed your file in the meantime? Adding that `if', for
> example?
Oops, you are so right.  I downgraded and found that zsh-3.1.6-dev-21 trips 
over the same thing.  Sorry about this misinformation!

And in fact, I moved the look statement into the if-then-else construct
lately.  I guess I haven't use it then for a while and happened to notice
that it doesn't work anymore after my zsh-upgrade.  Stupid coincidence. :-(

> It was always the case that syntactical constructs like if/the/else
> and loops were parsed completely. So if you do:
[...]
> the whole thing is parsed at once. When it is executed, the alias is
> defined, but in this case the functions are already parsed, too.
[...]
> It isn't special to zsh, either. All shells (have to) behave this way.

Oohhh!  This is not very self-evident.  Maybe that should go into the FAQ?
I split the if-clause in two and now it works.  Thank you!

> P.S.: [[..]] is faster than [..].
Thanks!

Thanks and sorry again!
 Andy.

-- 
 E-Mail: Andy@spiegl.de     URL: http://andy.spiegl.de
 PGP/GPG: see headers
                                o      _     _         _
  --------- __o       __o      /\_   _ \\o  (_)\__/o  (_)
  ------- _`\<,_    _`\<,_    _>(_) (_)/<_    \_| \   _|/' \/
  ------ (_)/ (_)  (_)/ (_)  (_)        (_)   (_)    (_)'  _\o_
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 "Technically, Windows is an operating system, which means that it
  supplies your computer with the basic commands it needs to suddenly,
  with no warning whatsoever, stop operating." - Dave Barry


^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: strange alias effects
  2000-05-29 13:32     ` Sven Wischnowsky
  2000-05-29 13:47       ` Andy Spiegl
@ 2000-05-29 17:24       ` Bart Schaefer
  1 sibling, 0 replies; 12+ messages in thread
From: Bart Schaefer @ 2000-05-29 17:24 UTC (permalink / raw)
  To: ZSH User List

On May 29, 12:27pm, Andy Spiegl wrote:
} Subject: Re: strange alias effects
}
} Bart Schaefer wrote,
} 
} > Did you happen to compile your dot-files with zcompile?
} No, never used that.
} And the same dot-files worked perfectly with 3.1.6.pws21.
} 
} > It's the same problem as "Bart Schaefer's rule" in FAQ 2.3

I misspoke slightly there.  It's the same as *the reason for* the rule,
which says:

 Define first those aliases you expect to use in the body of a function,
 but define the function first if the alias has the same name as the
 function.

On May 29,  3:32pm, Sven Wischnowsky wrote:
} Subject: Re: strange alias effects
}
} It was always the case that syntactical constructs like if/then/else
} and loops were parsed completely.  [...]  When it is executed, the alias
} is defined, but in this case the functions are already parsed, too.

And the effect of zcompile is that the entire file is parsed as one big
syntactic construct, so no aliases defined within the file are expanded
within the file. [*]

[*] Unless you first "source" the file to define them, and then compile
it with*out* using -U ... but that can also have unexpected results if
you have global aliases (alias -g).

Sven went on:
} It isn't special to zsh, either. All shells (have to) behave this way.

Csh doesn't, but then csh doesn't have functions.  Csh (the original one
from the old BSD Unix) parses and executes syntactic constructs in the
same pass; loops are, in effect, implemented with fseek.  It used to be
possible to create some pretty entertaining csh scripts that rewrote the
script file in place while it was executing.

-- 
Bart Schaefer                                 Brass Lantern Enterprises
http://www.well.com/user/barts              http://www.brasslantern.com

Zsh: http://www.zsh.org | PHPerl Project: http://phperl.sourceforge.net   


^ permalink raw reply	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2000-05-29 17:25 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2000-05-29  9:56 strange alias effects Andy Spiegl
2000-05-29 10:13 ` Bart Schaefer
2000-05-29 10:27   ` Andy Spiegl
2000-05-29 13:32     ` Sven Wischnowsky
2000-05-29 13:47       ` Andy Spiegl
2000-05-29 17:24       ` Bart Schaefer
2000-05-29 11:44 ` Andrej Borsenkow
2000-05-29 12:06   ` Andrej Borsenkow
2000-05-29 12:13     ` Andy Spiegl
2000-05-29 12:30       ` Andrej Borsenkow
2000-05-29 12:59         ` Andy Spiegl
     [not found]           ` <000301bfc96e$cf7af2b0$21c9ca95@mow.siemens.ru>
2000-05-29 13:13             ` Andy Spiegl

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).