I have the following script to execute "xset led" command on keypress but I cannot make it work for the command does not actually execute. Here is the script:
#!/bin/bash
res=$(echo "$(xset q)" | tr ";" "Scroll Lock")
if [[ $res == *"Scroll Lock: on"* ]]; then
echo $(xset led on)
else
echo $(xset led off)
fi
However when I execute echo $(xset led on) in the shell it works. Executing the script above outputs an empty line, though.
$resin quotes for comparison and use a single equals sign, i.e.if [ "$res" = *"Scroll Lock: on"* ]; then ... fi, but it seems like your script should work regardless. Oh, buttrwill only take the first character fromScroll Lock, not the whole thing! – wvxvw Nov 07 '17 at 09:26xsetinside a subshell, you could replaceecho $(xset led on)with justxset led onwith virtually the same effect. Also, you might want to putset +xbefore anything in your script to make Bash log every line it executes: this way you will know when something breaks. – wvxvw Nov 07 '17 at 14:11echo $(stuff)? – Kamil Maciorowski Mar 09 '20 at 16:42