[plug] alias problem

Russell Steicke r.steicke at bom.gov.au
Tue Jan 14 21:56:24 WST 2003


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'.

Sorry, forgot about aliases not taking positional parameters.  It's not
the pipe that's your problem but the $1.  In there it will be the first
parameter of the invoking shell, probably empty for interactive shells.
The args to md_bz will be at the end of the command, and cut will see
them.

> Next suggestion??

1.  Use a subshell and get rid of the -c:

  alias md_bz='( bzip2 -d | md5sum | cut -d" " -f1 ) < '

You'll _have_ to supply a file name to this when you run it, to go with
the redirection at the end.


2. Put it in a shell script.  This is my preferred option.  You have
much more control over parameters, and can do error checking.

> Craig




-- 
Russell Steicke

-- Fortune says:
His life was formal; his actions seemed ruled with a ruler.



More information about the plug mailing list