FAQ Search Today's Posts Mark Forums Read
» Video Reviews

» Linux Archive

Linux-archive is a website aiming to archive linux email lists and to make them easily accessible for linux users/developers.


» Sponsor

» Partners

» Sponsor

Go Back   Linux Archive > CentOS > CentOS

 
 
LinkBack Thread Tools
 
Old 03-06-2010, 07:47 AM
sync
 
Default Define an alias with an embeded awk command error ?

Hi, guys:
**
** I'm trying to define an alias in .cshrc* with the embeded awk command, like this :

alias checketh0* "ip add ls eth0 |awk '/inet/{print $2}' |sed -n '1p' "


Then i run "source ~/.cshrc" and run "checketh0" command in the terminal ,
but the result is the following :

** " inet 192.168.18.18/24 brd 192.168.18.255 scope global eth0"


but i want* this result :
192.168.18.18/24
*



How do I do it ? Any help will be highly appreciated.


Thanks for you help ~

_______________________________________________
CentOS mailing list
CentOS@centos.org
http://lists.centos.org/mailman/listinfo/centos
 
Old 03-06-2010, 11:34 AM
Alexander Dalloz
 
Default Define an alias with an embeded awk command error ?

Am 06.03.2010 09:47, schrieb sync:
> Hi, guys:
>
> I'm trying to define an alias in .cshrc with the embeded awk command,
> like this :
>
> alias checketh0 "ip add ls eth0 |awk '/inet/{print $2}' |sed -n '1p' "
>
> Then i run "source ~/.cshrc" and run "checketh0" command in the terminal ,
> but the result is the following :
>
> " inet 192.168.18.18/24 brd 192.168.18.255 scope global eth0"
>
> but i want this result :
> 192.168.18.18/24
>
>
> How do I do it ? Any help will be highly appreciated.
>
>
> Thanks for you help ~

Within your awk statement the "$2" is eaten and thus awk prints the
whole line.

You can bypass this using following in your .cshrc

set eth0=`/sbin/ip addr ls eth0 | awk '/inet/ { print $2; exit }'`
alias checketh0 "echo $eth0"

Alexander
_______________________________________________
CentOS mailing list
CentOS@centos.org
http://lists.centos.org/mailman/listinfo/centos
 

Thread Tools




All times are GMT. The time now is 04:30 PM.

VBulletin, Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright 2007 - 2008, www.linux-archive.org