#!/bin/bash
var = $(< /sys/class/leds/input3::numlock/brightness)
if $var = 0
then
notify-send 'Keyboard alert' 'Numlock Off.' --icon=dialog-information
else
notify-send 'Keyboard alert' 'Numlock On.' --icon=dialog-information
fi
exit 0
Can anyone tell me what is wrong with that as I have searching and searching as well as changing code over and over to no avail.
Now it complains that
var is not a command
well duh, it’s a variable that I want to test against.
The reason for this script is because my computer does not, sadly, have an LED for Numlock.
So any suggestions would be appreciated
Well… ok that’s not stackoverflow here, but that should be more correct:
#!/usr/bin/env bash
var=$(cat /sys/class/leds/input3::numlock/brightness)
if [[ $var -eq 0 ]]; then
notify-send 'Keyboard alert' 'Numlock Off.' --icon=dialog-information
elif [[ $var -eq 1 ]]; then
notify-send 'Keyboard alert' 'Numlock On.' --icon=dialog-information
fi
exit 0
You see there were a number of errors… variables for example must not have spaces between and conditions are like this: [[ expr != expr ]] in bash. Maybe have look at Bash scripting cheatsheet for a quick view.
What also should be mentioned is shellcheck to check your script for bad syntax.