Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR SHELL

my ip

ip route get 8.8.8.8 | awk -F"dev " 'NR==1{split($2,a," ");print a[1]}'
ip route get 8.8.8.8 | awk 'match($0,/dev (S*)/,a)&&$0=a[1]'
ip route get 8.8.8.8 | awk '{for(i=1;i<=NF;i++)if($i~/dev/)$0=$(i+1)}NR==1'

ip route get 8.8.8.8 | sed -E 's/.*?dev (S+) .*/1/;t;d'
ip route get 8.8.8.8 | sed 's/.*dev ([^ ]*).*/1/;t;d'
ip route get 8.8.8.8 | sed  -nE '1{s/.*?dev (S+) .*/1/;p}'

ip route get 8.8.8.8 | grep -oP 'dev K[^ ]+'
ens192
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #ip
ADD COMMENT
Topic
Name
7+8 =