[LBo] looking for command

Chris F.A. Johnson cfajohnson at teksavvy.com
Sun Mar 18 06:08:58 CET 2007


On Sat, 17 Mar 2007, Chris F.A. Johnson wrote:

> On Sat, 17 Mar 2007, Ray wrote:
>> 
>
>>  I'm looking for a command that will provide my own IP address
>>  suitable to pass as a commandline paramater to another program.
>>  I am aware of ifconfig and arp and if need be I can parse their
>>  output, (or just do it manually), but if there is an easier way....
>>  What I want is a command that just returns my internal ip address.
>>  i.e. command foo -> 192.168.0.104
>>  is there any such thing?

    Missing line:

sep=addr:

> if=eth0  ## adjust to taste
> temp=$(ifconfig "$if")
> temp=${temp#*"$sep"}
> ip=${temp%% *}

-- 
    Chris F.A. Johnson                      <http://cfaj.freeshell.org>
    ===================================================================
    Author:
    Shell Scripting Recipes: A Problem-Solution Approach (2005, Apress)


More information about the QnA mailing list