12 May 2020, 19:14

A slightly better version of the script that accepts 'on' and 'off' arguments. If no argument is given it toggles the backlight state

#!/bin/bash

filename='/sys/class/backlight/fb_ili9340/bl_power'
read -r state<$filename

if [ "$1" = "off" ]; then
        echo 1 > /sys/class/backlight/fb_ili9340/bl_power
elif [ "$1" = "on" ]; then
        echo 0 > /sys/class/backlight/fb_ili9340/bl_power
else
        echo "This command accepts the following arguments"
        echo "on - turns the backlight on"
        echo "off - turns the backlight off"
        echo "If no argument is given the backlight will toggle"
        echo "No state selcted, toggling."
        if [ "$state" = "0" ]; then
                echo 1 > /sys/class/backlight/fb_ili9340/bl_power
        else
                echo 0 > /sys/class/backlight/fb_ili9340/bl_power
        fi
fi