#!/bin/bash # File paths BRIGHTNESS_FILE="/sys/class/backlight/intel_backlight/brightness" MAX_BRIGHTNESS_FILE="/sys/class/backlight/intel_backlight/max_brightness" # Read the current brightness and maximum brightness values current_brightness=$(cat "$BRIGHTNESS_FILE") max_brightness=$(cat "$MAX_BRIGHTNESS_FILE") # Check if max_brightness is greater than 0 to avoid division by zero if [ "$max_brightness" -le 0 ]; then echo "Error: Max brightness is not a positive number." exit 1 fi # Calculate the brightness percentage and round to the nearest whole number brightness_percentage=$(echo "scale=0; ($current_brightness * 100 / $max_brightness)" | bc) # Output the brightness percentage echo "Backlight: ${brightness_percentage}%"