How to check if a value is greater than or equal to another?

if [ $xprintidle -ge 3000 ]; then
  [...stuff...]

Here's a quick explanation:

  • gt - greater than
  • ge - greater or equal than
  • $( ... ) becomes the output of the command inside the parentheses

You can use bash’s Arithmetic Expansion directly to compare integers:

#!/usr/bin/env bash
while :; do
  (( $(xprintidle) >= 3000 )) && xdotool mousemove_relative 1 1
  sleep 0.5
done

If you just want the single command, && is a simple way. Alternatively, use if:

#!/usr/bin/env bash
while :; do
  if (( $(xprintidle) >= 3000 )); then
    xdotool mousemove_relative 1 1
  fi
  sleep 0.5
done

I added a sleep call to the loop to pause for half a second each run – adapt it as needed.


To say if number is greater or equal to other you can use -ge. So your code can look like

#!/usr/bin/env bash
while true; do
    if [[ $(xprintidle) -ge 3000 ]]; then
        xdotool mousemove_relative 1 1
    fi
done

Tags:

Bash

Scripts