Re: Newbie alias question



On Tuesday 13 May 2008 16:37, wswilson wrote:

Running in bash mac os 10.4:

alias lc="wc -l $1 | awk '{print $1}'"

Why is the awk command not receiving the output from wc? Am I doing
this completely wrong?

You could do what you want just by doing

wc -l < "$1"

The problem with your code is that you can't pass positional parameters to
aliases. In your case (and in almost all cases, for that matter) you should
use a function instead of an alias:

$ lc () { wc -l "$1" | awk '{print $1}' }
$ cat file2
foo
bar
$ lc file2
2

--
All the commands are tested with bash and GNU tools, so they may use
nonstandard features. I try to mention when something is nonstandard (if
I'm aware of that), but I may miss something. Corrections are welcome.
.