[comp.unix.wizards] aliases vs. shell functions

hansm@cs.kun.nl (Hans Mulder) (08/28/90)

In article <738@primerd.PRIME.COM> milgr@teapot.prime.COM (Marc Milgram) writes:
>In article <2866@wyse.wyse.com>, bob@wyse.wyse.com (Bob McGowen x4312
>dept208) writes:
>|>As for using aliases for this function, only csh and ksh (if you have it)
>|>would be able to do this.
.
.
.
>aliases work in the bourne shell

No, they don't.

> (at least all of the /bin/sh's that I have used.)

Apparently, you have only used SysV-derived Un*xen.

>For example:
>
>ls()
>{
>  /bin/ls -CFb $@
>}

This is not an alias, it's a shell function.
Some /bin/sh's support these, others don't.
In particular, the /bin/sh that came with V7 didn't and
consequently the /bin/sh that comes with 4.[0-3]BSD still doesn't.

The Korn shell supports both aliases and shell functions; you can say either:

alias ls="/bin/ls -CBb"

or:

ls()
{
  /bin/ls -CFb "$@"		# Note the ""
}

and the effect is pretty much the same.


Hope this clarifies things a bit,

Hans Mulder	hansm@cs.kun.nl

hartman@ide.com (Robert Hartman) (08/29/90)

In article <2123@wn1.sci.kun.nl> hansm@cs.kun.nl (Hans Mulder) writes:
>...
>The Korn shell supports both aliases and shell functions; you can say either:
>
>alias ls="/bin/ls -CBb"
>
>or:
>
>ls()
>{
>  /bin/ls -CFb "$@"		# Note the ""
>}
>
>and the effect is pretty much the same.
>...

One further point.  A Korn shell alias does not handle command-line
arguments.  The Korn equivalent to a C-shell alias such as:

alias svi  'sccs edit -s \!*; vi \!*; sccs delget -s \!*'

would be:

svi() { # edit SCCS files
    sccs edit -s "$@"
    vi "$@"
    sccs delget -s "$@"
}

-r