[X-Unix] Argument variables in tcsh aliases

Lamar Goddard lamargoddard at gmail.com
Thu Aug 18 21:59:30 PDT 2005


On 8/17/05, Jeff Porten <civitan at jeffporten.com> wrote:
> The command in question is:
> 
> alias ipcount "sort $1 | cut -f 1 -d ' ' | uniq -c | sort -nr | more"


Try:

alias ipcount "sort \!:1 | cut -f 1 -d ' ' | uniq -c | sort -nr | more"


> Which works fine at the command line, but invoked from an alias will
> more the target file for one screen.  Control-C out of that puts it
> into some other process with no output; repeated breaks are needed to
> get back to a prompt.


That's because when the alias line is run, $1 is being interpreted and
your command ends up looking something like:

sort | cut -f 1 -d ' ' | uniq -c | sort -nr | more file

You need !:1 which means the first argument of the previous command,
in this case, ipcount.  You also need to escape the ! so that it
doesn't get interpreted until you run ipcount.  If you want to pass
multiple files to ipcount, use !:*, which means all arguments of the
previous comand.


Hope this helps.


-- 
Lamar Goddard
lamargoddard at gmail.com


More information about the X-Unix mailing list