Quote:
Originally posted by km4hr
I'm working on a bash script. I need a statement that gets the local computer's IP address. I see that 'ifconfig eth0' returns a bunch of stuff that contains the IP address but I then have to use grep/awk/sed or whatever to filter out just the address. Is there an easier way?
xyz
|
Not that I'm aware of. If there was a command that returned "just" the IP address, it is probably a shell script that called ifconfig | grep | sed etc...
FWIW: If you are new to shell scripting and familiar with programming - shell scripts support functions.
Example:
Code:
!#/bin/bash
# Function to extract IP address
extract_ip () {
ifconfig eth0 | grep | sed | etc...
}
# Set shell variable IP to ip address
IP=`extract_ip`