Bash script could be more efficient?

this works, but im sure im doing this wrong

#!/bin/bash
# VPN current status
# no vpn, home vpn, work vpn
#check home
if ifconfig | grep -q tun0; then
    home=1
else
    home=0
fi
#check work
if ifconfig | grep -q ppp0; then
    work=2
else
    work=0
fi
#add checks to var status
let status=home+work

if [ $status = 0 ]; then
    output=N
fi
if [ $status = 1 ]; then
    output=H
fi
if [ $status = 2 ]; then
    output=W
fi
if [ $status = 3 ]; then
    output=HW
fi

echo $output
exit

Why do it so complicated by adding the two?
Why not check if work && home are true?
Also you can echo directly. No need for an extra output var.

1 Like

fuuuuuuuck… yup, thats simple

Also, while it works fine here, ifconfig is technically deprecated.

Any of these would work:

nmcli connection show

ip a

ip l

1 Like