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

Re: strange alias effects



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@xxxxxxxxxxxxxxxxxxxxxxx



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