Why does this alias using awk not return a clean response like my other two?

Solution 1:

In your alias definition, $3 is actually expanded at the moment the alias is defined (although it doesn't look so at the first glance). If you type alias after defining your alias (to view defined aliases), you will see that your alias actually has the form

alias def='ip r | grep default | awk '\''{print }'\'''

and because of print alone in awk, the entire line returned by grep is printed.

Use the following to define the alias:

alias def="ip r | grep default | awk '{print \$3}'"

Then your alias will have the form:

alias def='ip r | grep default | awk '\''{print $3}'\'''

and it will work as you want.