On Sunday 29 July 2007 11:43, Dmitry wrote:
> ... For example :
> > alias test='echo $1 | grep qwerty; echo $1';

This is never a sensible alias. I'll say it again, positional parameters 
in aliases are not what they seem to be. They are not substituted with 
the parameters used when the alias is invoked, they are the parameters 
passed (or established within) the shell executing the alias.


> > test qwertyu

This is equivalent to issuing this command:

% echo $1 | grep qwert; echo $1 qwerty


> qwertyu

You get this results _only because the shell you're using has no 
positional parameters_.

Try this with your alias (by the way, calling it "test" is a very bad 
idea, since you usurp the test built-in and executable by doing so):

% set argumentTheFirst
% test qwerty

What do you think you'll see? It is:

argumentTheFirst qwerty


> But if we write this code in script we'll get
> qwertyu
> qwertyu

That's because putting the body of the alias in a script is nothing like 
that alias.


> Thats why I use aliases only on simple commands and scripts on
> others.

Aliases never were meant to handle positional parameter substitution. 
It's critical to know this or you'll continue to be frustrated and 
confused by their behavior.


> --
> WBR, Dmitry.


Randall Schulz
-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to