DEV Community

Discussion on: Make Your Tmux Status Bar 100% Better With Bash

Collapse
 
brandonwallace profile image
brandon_wallace • Edited

@vlasales I refactored my code and came up with this.

# Loop through the interfaces and check for the one that is up.
    for iface in /sys/class/net/*/operstate; do
        if [ "$(echo $iface | awk -F'/' '{print $5}')" != "lo" ]; then
            if [ "$(cat $iface)" == "up" ] ; then
                interface=$(echo $iface | awk -F'/' '{print $5}')
                printf "%s " "$(ip addr show $interface | awk '/inet /{print $2}')"
            fi
        fi
    done 
Enter fullscreen mode Exit fullscreen mode

But the code you wrote is shorter so I added it to my article. The old code had two loops but one loop is better than two. Thanks.