don't recurse on alias expansion [was Re: SPUG:Re: ~damian/bin scripts. [moreso Offtopic]]

Michael R. Wolf MichaelRunningWolf at
Wed Jan 22 17:08:03 CST 2003

Jeremy Mates <jmates at> writes:

> * Daniel James <djames at>
> > You have to get used to typing cwd though; if you name your function
> > "cd" then you will get an infinite loop--someone here may know how to
> > get around your alias problem though.
> cd(){
>   builtin cd $*
>   ls
> }

Korn shell does it by quoting the name.  Any quoting mechanism
(single, double, backslash) on the name prevents alias substitution.
That's the idea.  Since I don't have a ksh handy, I haven't tested

    alias cd='\cd "$@" && ls'

I also like putting in the && short-circuit test.  What if the cd
doesn't succeed?

Another way to make it work (for non-built-ins) would be to use an
absolute path name, though this isn't as portable across different
machines.  Aliases aren't expanded for names that look like absolute

    alias ls='/bin/ls $LS_FLAGS "$@"'

Michael R. Wolf
    All mammals learn by playing!
        MichaelRunningWolf at

More information about the spug-list mailing list