Building an awk alias in (t)csh

Darin McGrew mcgrew at ichthous.Eng.Sun.COM
Thu Jan 17 09:30:09 AEST 1991


edh at 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 at 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.'"



More information about the Comp.unix.shell mailing list