[plug] alias problem

James Devenish devenish at cyllene.uwa.edu.au
Tue Jan 14 22:19:01 WST 2003


On Tue, Jan 14, 2003 at 09:56:24PM +0800, Russell Steicke wrote:
> On Tue, Jan 14, 2003 at 09:30:30PM +0800, Craig Dyke wrote:
> > OK ... understand logic behind that, but, found that I now have a different problem.
> > 
> > It would seem that the | is not my friend.
> > If I do:	alias md_bz='bzip2 -cd $1'	<-- no problems
> > 
> > but the moment the pipe comes in:
> > 		alias md_bz='bzip2 -cd $1 | md5sum'	<-- or any other command after pipe
> > 
> > I get:		bzip2: I won't read compressed data from a terminal.
> > 		bzip2: For help, type: `bzip2 --help'.

Russell's right in his previous e-mail, but just to clarify what was
happening above: it's nothing to do with the pipe per se. `bzip` on its
own will give you the error. It's just that with the first definition of
md_bz, `md_bz x` would expand to `bzip2 -cd x`, which is satisfactory
for bzip2 (assuming x exists). On the other hand, the second definition
would expand to `bzip2 -cd | md5sum x`, which is not what you wanted.
(As Russell mentioned, $1 is probably empty in your shell -- and it
doesn't work like a positional parameter in your alias.)

PS. To save the overhead of starting a new shell process (or perl or...)
your shell may support 'functions'. Instead of `alias md_bz=...` you
might be able to use something like:

function md_bz {
	if [[ $# -ne 1 ]]; then # ensure exactly one argument
		echo Usage: md_bz '<filename>'
		return
	fi
	bzip2 -cd $1 | md5sum
}

This should be more efficient (esp. if being repeatedly invoked) than
having an executable shell script in its own file but and has the
added advantage that if you share your aliases/startup file on several
computers, they can all benefit from this function without having to
have the individual shell scripts copied across one-by-one.

YMMV.




More information about the plug mailing list