Skip to content

Instantly share code, notes, and snippets.

@ultimatecoder
Created March 30, 2017 12:01
Show Gist options
  • Save ultimatecoder/52ba5a6bc082e02b78c61d623cd75d59 to your computer and use it in GitHub Desktop.
Save ultimatecoder/52ba5a6bc082e02b78c61d623cd75d59 to your computer and use it in GitHub Desktop.
Below script is written for managing brightness value of my computer. I have written this just to play with bash shell scripting. It is purly for learning purpose.
#!/bin/bash
path=/sys/class/backlight/radeon_bl0/brightness
display_usage() {
cat << EOF
Usage: brightness [-h] VALUE
Set the screen brightness according to given value.
-h Will display the help.
VALUE Screen brightness value strictly between 0 to 100.
EOF
}
while getopts h option
do
case $option in
h)
display_usage
exit 0
;;
*)
display_usage
exit 1
;;
esac
done
brightness=$1
if [[ "$brightness" = +([0-9]) ]] && ((brightness >= 0 && brightness <= 100))
then
sudo tee "$path" > /dev/null <<< "$brightness"
else
echo "ERROR: The brightness value should be interger between 0 to 100. See usage by 'brightness -h'"
exit 1
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment