[comp.unix.shell] Building an awk alias in

edh@ux.acs.umn.edu (Eric D. Hendrickson) (01/17/91)

I would like to make an alias like this:

alias	where	"who | grep \!:1 | awk '{print $6}' -"

which would output the originating host of the user caled for.  I have
tried all kinds of permutations of quote characters, etc, with no luck.  I
ended up making the awk portion into a one-liner script and piping to that
instead.

This command works fine on the command line, but not as an alias.  Can
anybody tell me what I am doing wrong/should do?

Thanks very much,
			--eric
-- 
/----------"Oh carrots are divine, you get a dozen for dime, its maaaagic."--
|Eric (the "Mentat-Philosopher") Hendrickson	  Academic Computing Services
|edh@ux.acs.umn.edu	   The game is afoot!	      University of Minnesota
\-"What does 'masochist' and 'amnesia' mean?   Beats me, I don't remember."--

mcgrew@ichthous.Eng.Sun.COM (Darin McGrew) (01/17/91)

edh@ux.acs.umn.edu (Eric D. Hendrickson) writes:
>I would like to make an alias like this:
>
>alias	where	"who | grep \!:1 | awk '{print $6}' -"

As you may have already figured out, the $6 gets expanded at the
time that the alias command is executed, because it is within the
double quotes.  You need to protect the $6 from being expanded by
the shell when the alias command is executed, and you also need
to protect it from being expanded by the shell when the alias
itself is being executed.  The following works:

  alias	where	"who | grep \!:1 | awk" \''{print $6}'\' -

because the unescaped single quotes protect the $6 from expansion
when the alias command is executed, and the escaped single quotes
become part of the alias and protect the $6 from expansion when
the alias itself is executed.

                 Darin McGrew     "The Beginning will make all things new,
           mcgrew@Eng.Sun.COM      New life belongs to Him.
       Affiliation stated for      He hands us each new moment saying,
identification purposes only.      'My child, begin again.
				    My child, begin again.'"