Both the following work here (CentOS 5).
ip addr show eth0 | awk '$1 == "inet" {gsub(/\/.*$/, "", $2); print $2}'
ifconfig eth0 | awk '/inet addr/ {gsub("addr:", "", $2); print $2}'
For OS X (v10.11 (El Capitan) at least):
ifconfig en0 | awk '$1 == "inet" {print $2}'
More Related Contents:
- Setting environment variables on OS X
- How to restore .bash_profile on a mac? None of my unix terminal are working [closed]
- Running a command in a new Mac OS X Terminal window
- Setting PATH environment variable in OSX permanently
- Why does cURL return error “(23) Failed writing body”?
- How to use GNU sed on Mac OS 10.10+, ‘brew install –default-names’ no longer supported
- Date command does not follow Linux specifications (Mac OS X Lion)
- Variables overwriting text problem with “echo” in Bash
- Bash script absolute path with OS X
- Mac OS: /usr/bin/env: bad interpreter: Operation not permitted
- How do I create a Bash alias?
- Why isn’t DYLD_LIBRARY_PATH being propagated here?
- How to set keyboard shortcuts to jump to beginning/end of line? [closed]
- Installing Homebrew on macOS
- Difference between .profile and .bash_profile on Snow Leopard
- What is the Unix command to create a hardlink to a directory in OS X?
- how to pass command-line arguments to a program run with the open command?
- How to make OS X to read .bash_profile not .profile file
- How to get the PID of a process by giving the process name in Mac OS X ?
- Add app to OSX “Login Items” during a Package Maker installer postflight script
- Mac OS X 10.9 – setting permanent environment variables
- Run a script only at shutdown (not log off or restart) on Mac OS X
- How can I manipulate text in bash? [closed]
- sed not giving me correct substitute operation for newline with Mac – differences between GNU sed and BSD / OSX sed [duplicate]
- Mongod complains that there is no /data/db folder
- Error when using ‘sed’ with ‘find’ command on OS X: “invalid command code .”
- How do I create a nice-looking DMG for Mac OS X using command-line tools?
- `pg_tblspc` missing after installation of latest version of OS X (Yosemite or El Capitan)
- macOS window with integrated title bar and toolbar?
- Cannot create a symlink inside of /usr/bin even as sudo [closed]