i'm trying to create a bash script which lets me toggle external screens based on which screens are connected to my laptop (I have two ports). To be honest, my expertise in bash is limited, so this could also be a logical bash mistake. I have the following script:
#!/bin/bash
HDMI=$(xrandr | grep 'HDMI' | cut -d ' ' -f 1)
LVDS=$(xrandr | grep 'LVDS' | cut -d ' ' -f 1)
VGA=$(xrandr | grep 'VGA' | cut -d ' ' -f 1)
HDMI_CON=$(xrandr | grep "$HDMI connected")
HDMI_DIS=$(xrandr | grep "$HDMI disconnected")
VGA_CON=$(xrandr | grep "$VGA connected")
VGA_DIS=$(xrandr | grep "$VGA disconnected")
if [ VGA_CON ] && [ HDMI_CON ]
then
echo "VGA CON, HDMI CON"
elif [ VGA_CON ] && [ HDMI_DIS ]
then
echo "VGA CON, HDMI DIS"
elif [ VGA_DIS ] && [ HDMI_CON ]
then
echo "VGA DIS, HDMI CON"
else
echo "VGA DIS, HDMI DIS."
fi
What happens is that VGA_CON && HDMI_CON always return true, which results in my script always thinking both displays are connected. Anyone who can enlighten me regarding whats happening?