I have the following line of code in a bash script:
# Is there an external monitor connected via HDMI?
has_external=$(xrandr 2> /dev/null | grep -q 'HDMI[0-9] connected')
The output of xrandr
could contain this:
HDMI1 connected (normal left inverted right x axis y axis)
HDMI2 disconnected (normal left inverted right x axis y axis)
HDMI3 disconnected (normal left inverted right x axis y axis)
For the life of my I can't figure out why the has_external
variable always evaluates to true, even if "HDMI1 connected" is not in the output of xrandr
. Any ideas?