[LBo] looking for command
Chris F.A. Johnson
cfajohnson at teksavvy.com
Sun Mar 18 16:58:26 CET 2007
On Sun, 18 Mar 2007, TerryJ wrote:
> Chris F.A. Johnson wrote:
>> 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%% *}
>
> How do you get a print of that?
The same way you print anything:
printf "%s\n" "$ip"
Or:
printf "%s\n" "${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