I'm glad we could help you figure it out.
However, now I'd like to comment on your script. There are some improvements we could make to it. First some general advice:
1) When using advanced shells like
bash or
ksh, it's recommended to use
[[..]] for string/file tests, and
((..)) for numerical tests. Avoid using the old
[..] test unless you specifically need POSIX-style portability.
http://mywiki.wooledge.org/BashFAQ/031
http://mywiki.wooledge.org/ArithmeticExpression
2)
$(..) is highly recommended over `..`
3)
process substitution is usually better than a pipe for feeding a while loop.
4) Your formatting could be more consistent, and a few comments explaining what the code is doing would help make it more understandable.
Now for a few specific lines:
5)
What's the "17" for? All this does is return as always true, so the loop never ends. If you want a continuous loop, then just use "
while true", with
true being the shell built-in command.
But I question whether this loop is even necessary. The inner loop should continue to run for as long as the input doesn't issue an EOF. Of course I don't know anything about the
aseqdump command, so perhaps it does.
6)
I thought about combining this array-setting line with the outside loop, and just using
read -a there. But then again I don't know what the exact input line format looks like, so I decided it would be better to keep it this way. But it's still safer to use
read to break up the line than to rely on direct shell word-splitting. You don't have to leave the variable unquoted that way.
7)
Code:
b=${a[5]}
if [ $b ]; then
lenny=${#b}
last=${b:$lenny-1:$lenny}
if [ "$last" == "," ]; then
b=${b:0:$lenny-1}
fi
fi
The nearest I can deduce, the only purpose of this is to remove any possible trailing commas (an example of how comments help out). If so, you've made it ten times more complex than it has to be. A single
parameter substitution is all that's required to do that.
8)
Code:
"60") if [ "${a[2]}" == "on" ]; then `/root/pikey/./xsendkeycode 54 1`; else `/root/pikey/./xsendkeycode 54 0`;fi;; #echo -ne "c"; echo -ne "c">>textfile ;;
Several problems here, starting with formatting. Idividual commands should generally be kept on separate lines. There's no shortage of space in a shell script.
But more to the point, You use the same basic code over and over inside the
case statement, making it a perfect candidate for a shell
function. Write once, use many, and help keep the code clean.
Third, you're running the commands inside
`..` brackets. In addition to suggestion #2 above, I can't see how this would even work.
command substitutions like this are replaced with the text output of the command, and then the shell attempts to execute that line. So, unless the text expands into a valid command, it shouldn't work at all. I think you just want to leave them off.
Finally, the extra "
/./" in the command path is kind of pointless and ugly. Not that it really hurts anything though.
So anyway, here's my attempt at a revised version of the script. I didn't try to change anything major in the way it functioned, but only tried to reorganize it in a clearer fashion. I can't guarantee that I got everything right, since I don't know what the input looks like or for that matter anything else about it what it's rally doing.
But hopefully you can work around any errors.
Code:
#!/bin/bash
outfile=textfile
PATH="/root/pikey:$PATH"
f_sendkey() {
case ${a[2]} in
on) xsendkeycode "$1" 1 ;;
*) xsendkeycode "$1" 0 ;;
esac
#echo -ne "$2" >>"$outfile"
}
while true; do
olea=""
while read -r line ; do
if [[ $olea != $line ]]; then
read -ra a <<<"$line"
b=${a[5]%,}
c=${a[4]}
case "$b" in
60) f_sendkey 54 c ;;
62) f_sendkey 40 d ;;
65) f_sendkey 41 f ;;
67) f_sendkey 42 g ;;
69) f_sendkey 38 a ;;
71) f_sendkey 56 b ;;
64) if [[ $c == controller && ${a[7]} -eq 127 ]]; then
xsendkeycode 62 1
elif [[ $c == controller ]]; then
xsendkeycode 62 0
else
f_sendkey 26 e
fi
;;
esac
fi
olea=$line
done < <( aseqdump -p 20 )
done
exit 0