[CentOS] Define an alias with an embeded awk command

m.roth at 5-cent.us m.roth at 5-cent.us
Tue Dec 15 19:56:03 UTC 2009


> On Mon, Dec 14, 2009 at 7:20 PM, Majian <jiannma at gmail.com> wrote:
>> But After  I  edit the command "alias checketh0  "echo `ifconfig eth0 |
>> grep
>> 'inet addr:' |awk '{print $2}' | cut -c 6-`"  in my .cshrc file
>> The screen displays this :
>> innet addr:192.168.7.24 Bcast:192.168.7.255 Mask :255.255.255.0
>
> I think you need to escape either the {} or $ in the awk command, or
> else not use it. Try:
>
> [root@ ~]# alias  checketh0 "ifconfig eth0 | grep 'inet addr:'|cut -d
> ':' -f 2|cut -f 1 -d ' '"
> [root@ ~]# checketh0
> 12.17.152.3
<snip>
Simpler, and more obvious to read:

/sbin/ifconfig eth0 | awk '{if ( $0 ~ /inet addr:/ ) {print substr($2,6)}}'

     mark "awk! awk!"




More information about the CentOS mailing list