Newsgroups: comp.os.minix
Subject: Re: aliases in sh or ash?
References: <3761823D.E2D844EC@Wireless.Com>
Organization: Syracuse University, Syracuse
From: mcconnel@hydra.syr.edu (Terry R. McConnell)
NNTP-Posting-Host: hydra.syr.edu
Message-ID: <376270e9.0@news.syr.edu>
Date: 12 Jun 1999 10:38:33 -0500
X-Trace: 12 Jun 1999 10:38:33 -0500, hydra.syr.edu
Lines: 56
Path: star.cs.vu.nl!newsfeed.amsterdam.nl.net!sun4nl!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!news.syr.edu!hydra.syr.edu!mcconnel
Xref: star.cs.vu.nl comp.os.minix:35806

In article <3761823D.E2D844EC@Wireless.Com>,
Mike Cheponis  <Mike@Wireless.Com> wrote:
>Is there a way to create an "alias" in sh or ash?  I would like to alias
>ls to "ls -F" and to alias ll to "ls -ali".
>
>I can do this with csh and bash, but I can't seem to figure out how to
>do this with sh or ash in Minix.

Ash and other Bourne shell derivatives support shell functions, which are
much more powerful and flexible than aliases. You can define a shell function
at the command line or in a shell script using the following syntax:

name () {

# body of shell function here

}

The body can contain any commands or shell programming constructs that you
would normally put in a script or use at the command line. After being
defined, a shell function can be invoked by typing its name followed by
any arguments you wish to pass to it. (Arguments are available to the code
inside the block definition of the function as positional parameters
$0, $1, ...)

Example:

$ greet_me () {
>
>	echo "$0: Hello there, $1"  # You don't type >. It is secondary prompt.
>	return 0   # This returns exit status 0
>}

$ greet_me God
greet_me: Hello there, God
$ echo $?
0

I'm not sure Minix's /bin/sh, which is pretty minimal, supports shell 
functions, but ash does. Bash, also a Bournish shell, does support aliases,
but only in a half-hearted way. 

For your application, you could define the following in .ashrc (untested):

ll () {

	shift  # don't want "ll" in $*
	ls -ali "$*"
	return $?   # return exit status of ls (optional here)
} 

-- 
************************************************************************
Terry R. McConnell   Mathematics/304B Carnegie/Syracuse, N.Y. 13244-1150
trmcconn@syr.edu                            http://barnyard.syr.edu/~tmc 
************************************************************************
