Mailing List Archive

Support open source code!


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: tlug: Re: file counting



> > Are you sure that you can use tokens like $1 in an alias?
> 
> It IS acting wierd and yes, $1 does work:

No, if you're using bash, you may not use argument substitution.
The reason why the "psg" sample;

> schweiz:~$ alias psg
> alias psg='ps -aux | grep  $1'
> schweiz:~$ psg schweiz
> schweiz    831  0.0  3.5   94  388 pp0 S    21:48   0:00 -bash

is working is because the $1 is the last argument,
which is usually unset in the interactive shell,
so it's neglected by bash.  I.e.,

	input-->	psg schweiz
	expanded-->	ps -aux | grep schweiz

Your "find" example,

	alias numf='find $1 -type f | wc -l'

would be interprited like this;

	input-->	numf ~/Mail
	expanded-->	find -type f | wc -l ~/Mail

If you want to handle arguments in bash, you should use
a script file as you've done in the first place, OR
write a function in your ~/.bashrc like;

	numf() { find $1 -type d | wc -l }


Here's the quotation from `man bash';

	There is no mechanism for using arguments in the  replace-
	ment  text,  as  in csh.  If arguments are needed, a shell
	function should be used.


--- Kenichiro TANAKA
---------------------------------------------------------------
Next Nomikai: 20 November, 19:30 Tengu TokyoEkiMae 03-3275-3691
Next Meeting: 12 December, 12:30 Tokyo Station Yaesu central gate
---------------------------------------------------------------
Sponsor: PHT, makers of TurboLinux http://www.pht.co.jp


Home | Main Index | Thread Index

Home Page Mailing List Linux and Japan TLUG Members Links