0

I need some Specs and Data from Number of Latops in a ini-file. When I try to get the IP-Adress with ip addr list <interface> nothing happens in the script. Not even a Error.

I try to quote stuff in my code. Nothing change.

for w2 in /sys/class/net/wl* 
    do 
        w2i=$(basename $w2)
        echo $w2i
        addr=$(ip -o -4 addr list $w2i | awk '{print $4}' | cut -d/ -f1)
        echo $addr
        echo -e "$w2i=$addr"
done

I Think maybe it is because of the Varibales but this fails also (interface is set 'manually'):

for w2 in /sys/class/net/wl* 
    do 
        w2i=$(basename $w2)
        echo $w2i
        addr=$(ip -o -4 addr list wlp3s0 | awk '{print $4}' | cut -d/ -f1)
        echo $addr
        echo -e "$w2i=$addr"
done 

When i run the script i get wlp3s0 and i must close the script with ctl-c. When i run ip -o -4 addr list wlp3s0 | awk '{print $4}' | cut -d/ -f1 it gives me my ip like i expected.

EDIT

I just need to wirte the full-path of the ip-command. Can somebody explain why i have to do this? And especially it is not necessary for cut or awk that also based in /usr/bin/?

for w2 in /sys/class/net/wl* 
    do 
        w2i=$(basename $w2)
        echo $w2i
        addr=$(/usr/bin/ip -o -4 addr list "$w2i" | awk '{print $4}' | cut -d/ -f1)
        echo $addr
        echo -e "$w2i=$addr"
done
}
mrflash818
  • 930
  • 13
  • 24
FlashGGG
  • 5
  • 2
  • This might help: [How to debug a bash script?](http://unix.stackexchange.com/q/155551/74329) – Cyrus Nov 09 '19 at 13:23
  • 1
    Check content of `$PATH` in your script. – Cyrus Nov 09 '19 at 14:02
  • Do you have `ip` defined as a function or something in the script? Try putting `type ip` in the script to see what it thinks `ip` means in that context. – Gordon Davisson Nov 09 '19 at 16:59
  • @GordonDavisson thank you! yes, ip was a function a few lines before in the script. I forgot it because I wrote that many days ago. and obviously I am blind. – FlashGGG Nov 09 '19 at 17:40

0 Answers0