I'm kind of embarrassed to ask but I can't get this if-statement working.
I have a bash script that automates some stuff at startup depending on the number of monitors I have.
When my external monitor is plugged in, I want to have a different setup than when I'm working on my laptop without external monitor.
displays=$(xrandr | grep -sw 'connected' | wc -l) # the manount of displays
echo "$displays"
if [ $displays==1 ]; then
echo "1 monitor"
else
echo "2 monitors"
fi
When I have my external monitor plugged in and $displays is 2, I get the echo "1 monitor"?
I really dislike bash scripting... for simple automation is fine but I find the syntax to be horrendous to look at, and even worse, memorize because of all the backwards compatibility features it has.
What I like to do is make absolutely sure I got it right by throwing everything that is allowed. That way I can be sure it works:
if [[ "${displays}" -eq 1 ]]
then
echo "1 monitor"
else
echo "2 monitors"
fi