1

I'd like to create a simple alias:

alias gate=route | grep default | awk '{print $2}'

and even though the command does work in terminal, it's not working through ~/.bash_aliases. Thanks.

1 Answer 1

2

You need to put quotes around the pipeline - being careful to ensure that $2 doesn't get expanded by the shell. So for example

alias gate='route | grep default | awk "{print \$2}"'

or

alias gate="route | grep default | awk '{print \$2}'"

Note that awk can do pattern matching - so you don't really need grep:

alias gate="route | awk '/^default/ {print \$2}'"
0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .