Skip to content

Instantly share code, notes, and snippets.

@smudge1977
Created November 16, 2023 10:34
Show Gist options
  • Save smudge1977/77d81679cffdc7a455c2566d6b03c793 to your computer and use it in GitHub Desktop.
Save smudge1977/77d81679cffdc7a455c2566d6b03c793 to your computer and use it in GitHub Desktop.
Get IP v4 from ip a output
# Regex to match the first IP address for the interface br0
REGEX="(\b25[0-5]|\b2[0-4][0-9]|\b[01]?[0-9][0-9]?)(\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)){3}"
[[ $(ip -4 address | grep -A1 "br0") =~ $REGEX ]]
echo "${BASH_REMATCH[0]}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment