Hi ,all : I'm trying to define an alias with an embeded awk command: alias checketh0 `ifconfig eth0 |grep 'inet addr:' |awk '{prinrt $2}' |cut -c 6- ` After I edit it in the .cshrc file and run "source .cshrc" , I run the "checketh0" command in the terminal , the screen displays the "192.168.7.24: Command not found " Why does is it ?Any help will be highly appreciated. note: I'm using csh shell. Thanks for you help. -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.centos.org/pipermail/centos/attachments/20091215/be488c75/attachment.html>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <meta content="text/html; charset=ISO-8859-1" http-equiv="Content-Type"> </head> <body text="#000000" bgcolor="#ffffff"> On 15/12/09 15:40, Majian wrote: <blockquote cite="mid:eb686fc70912142040l4fe7c660w1534c160d92506b1@mail.gmail.com" type="cite">Hi ,all :<br> <br> I'm trying to define an alias with an embeded awk command:<br> <br> alias checketh0 `ifconfig eth0 |grep 'inet addr:' |awk '{prinrt $2}' |cut -c 6- `<br> <br> After I edit it in the .cshrc file and run "source .cshrc" , I run the "checketh0" command in the terminal ,<br> the screen displays the "<a moz-do-not-send="true" href="http://192.168.7.24">192.168.7.24</a>: Command not found "<br> <br> <br> Why does is it ?Any help will be highly appreciated.<br> <br> note: I'm using csh shell.<br> </blockquote> Hi Majian,<br> <br> It's not an issue with awk but with the way the alias is interpreted. It tries to run the result of the commands in between the ` ` as a command itself. To get around it, try: <br> <br> # alias checketh0="echo `ifconfig eth0 | grep 'inet addr:' |awk '{print $2}' | cut -c 6-`"<br> <br> Cheers,<br> <br> Andrew<br> </body> </html>
On Mon, Dec 14, 2009 at 8:54 PM, Andrew Harley <andrew at promed.com.au> wrote:> > It's not an issue with awk but with the way the alias is interpreted. It > tries to run the result of the commands in between the ` ` as a command > itself. To get around it, try: > > # alias checketh0="echo `ifconfig eth0 | grep 'inet addr:' |awk '{print $2}' | cut -c 6-`"Er, no, the double quotes will mean that the backtick command is expanded at the time the alias is defined rather than at the time it is run. So you'll get the ifconfig output from the time the shell started, always. You want alias checketh0 'echo `ifconfig eth0 | grep "inet addr:" |awk '\''{print $2}'\'' | cut -c 6-`'