Wie bringe ich ein Shell-Skript dazu, mehrere if-Anweisungen endlos zu durchlaufen?

Wie bringe ich ein Shell-Skript dazu, mehrere if-Anweisungen endlos zu durchlaufen?

Ich habe ein Shell-Skript auf Grundlage einer Reihe von Snippets und Tutorials erstellt, die ich gelesen habe. Ich kann einfach nicht herausfinden, wie ich einen Syntaxfehler beheben und es zum Laufen bringen kann. Die Terminalausgabe lautet:

./afkscript.sh: 2 ./afkscript.sh: Syntax error: "(" unexpected ( expecting "done")

Nach dem, was ich in den Tutorials gelesen habe, sind diese Klammern erforderlich. Hier ist mein Skript (mit ersetztem Fensternamen):

while true 
do
sleep $[ ( $RANDOM % 10 ) + 1 ]s
DIFF=$((46-1+1))
R=$ ( ( $ ( ($RANDOM%DIFF) ) +1) )
if [[ "R" -eq 1 ]]; then
xdotool search --name "WINDOWNAME" windowactivate --sync
sleep .05
xdotool type "a"
elif [[ "R" -eq 2 ]]; then
xdotool search --name "WINDOWNAME" windowactivate --sync
sleep .05
xdotool type ""
elif [[ "R" -eq 3 ]]; then
xdotool search --name "WINDOWNAME" windowactivate --sync
sleep .05
xdotool type "d"
elif [[ "R" -eq 4 ]]; then
xdotool search --name "WINDOWNAME" windowactivate --sync
sleep .05
xdotool type "f"
elif [[ "R" -eq 5 ]]; then
xdotool search --name "WINDOWNAME" windowactivate --sync
sleep .05
xdotool type "g"
elif [[ "R" -eq 6 ]]; then
xdotool search --name "WINDOWNAME" windowactivate --sync
sleep .05
xdotool type "h"
elif [[ "R" -eq 7 ]]; then
xdotool search --name "WINDOWNAME" windowactivate --sync
sleep .05
xdotool type "j"
elif [[ "R" -eq 8 ]]; then
xdotool search --name "WINDOWNAME" windowactivate --sync
sleep .05
xdotool type "k"
elif [[ "R" -eq 9 ]]; then
xdotool search --name "WINDOWNAME" windowactivate --sync
sleep .05
xdotool type "l"
elif [[ "R" -eq 10 ]]; then
xdotool search --name "WINDOWNAME" windowactivate --sync
sleep .05
xdotool type ";"
elif [[ "R" -eq 11 ]]; then
xdotool search --name "WINDOWNAME" windowactivate --sync
sleep .05
xdotool type "'"
elif [[ "R" -eq 12 ]]; then
xdotool search --name "WINDOWNAME" windowactivate --sync
sleep .05
xdotool type "\"
elif [[ "R" -eq 13 ]]; then
xdotool search --name "WINDOWNAME" windowactivate --sync
sleep .05
xdotool type "q"
elif [[ "R" -eq 14 ]]; then
xdotool search --name "WINDOWNAME" windowactivate --sync
sleep .05
xdotool type "w"
elif [[ "R" -eq 15 ]]; then
xdotool search --name "WINDOWNAME" windowactivate --sync
sleep .05
xdotool type "e"
elif [[ "R" -eq 16 ]]; then
xdotool search --name "WINDOWNAME" windowactivate --sync
sleep .05
xdotool type "r"
elif [[ "R" -eq 17 ]]; then
xdotool search --name "WINDOWNAME" windowactivate --sync
sleep .05
xdotool type "t"
elif [[ "R" -eq 18 ]]; then
xdotool search --name "WINDOWNAME" windowactivate --sync
sleep .05
xdotool type "y"
elif [[ "R" -eq 19 ]]; then
xdotool search --name "WINDOWNAME" windowactivate --sync
sleep .05
xdotool type "u"
elif [[ "R" -eq 20 ]]; then
xdotool search --name "WINDOWNAME" windowactivate --sync
sleep .05
xdotool type "i"
elif [[ "R" -eq 21 ]]; then
xdotool search --name "WINDOWNAME" windowactivate --sync
sleep .05
xdotool type "o"
elif [[ "R" -eq 22 ]]; then
xdotool search --name "WINDOWNAME" windowactivate --sync
sleep .05
xdotool type "p"
elif [[ "R" -eq 23 ]]; then
xdotool search --name "WINDOWNAME" windowactivate --sync
sleep .05
xdotool type "["
elif [[ "R" -eq 24 ]]; then
xdotool search --name "WINDOWNAME" windowactivate --sync
sleep .05
xdotool type "]"
elif [[ "R" -eq 25 ]]; then
xdotool search --name "WINDOWNAME" windowactivate --sync
sleep .05
xdotool type "1"
elif [[ "R" -eq 26 ]]; then
xdotool search --name "WINDOWNAME" windowactivate --sync
sleep .05
xdotool type "2"
elif [[ "R" -eq 27 ]]; then
xdotool search --name "WINDOWNAME" windowactivate --sync
sleep .05
xdotool type "3"
elif [[ "R" -eq 28 ]]; then
xdotool search --name "WINDOWNAME" windowactivate --sync
sleep .05
xdotool type "4"
elif [[ "R" -eq 29 ]]; then
xdotool search --name "WINDOWNAME" windowactivate --sync
sleep .05
xdotool type "5"
elif [[ "R" -eq 30 ]]; then
xdotool search --name "WINDOWNAME" windowactivate --sync
sleep .05
xdotool type "6"
elif [[ "R" -eq 31 ]]; then
xdotool search --name "WINDOWNAME" windowactivate --sync
sleep .05
xdotool type "7"
elif [[ "R" -eq 32 ]]; then
xdotool search --name "WINDOWNAME" windowactivate --sync
sleep .05
xdotool type "8"
elif [[ "R" -eq 33 ]]; then
xdotool search --name "WINDOWNAME" windowactivate --sync
sleep .05
xdotool type "9"
elif [[ "R" -eq 34 ]]; then
xdotool search --name "WINDOWNAME" windowactivate --sync
sleep .05
xdotool type "0"
elif [[ "R" -eq 35 ]]; then
xdotool search --name "WINDOWNAME" windowactivate --sync
sleep .05
xdotool type "-"
elif [[ "R" -eq 36 ]]; then
xdotool search --name "WINDOWNAME" windowactivate --sync
sleep .05
xdotool type "="
elif [[ "R" -eq 37 ]]; then
xdotool search --name "WINDOWNAME" windowactivate --sync
sleep .05
xdotool type "z"
elif [[ "R" -eq 38 ]]; then
xdotool search --name "WINDOWNAME" windowactivate --sync
sleep .05
xdotool type "x"
elif [[ "R" -eq 39 ]]; then
xdotool search --name "WINDOWNAME" windowactivate --sync
sleep .05
xdotool type "c"
elif [[ "R" -eq 40 ]]; then
xdotool search --name "WINDOWNAME" windowactivate --sync
sleep .05
xdotool type "v"
elif [[ "R" -eq 41 ]]; then
xdotool search --name "WINDOWNAME" windowactivate --sync
sleep .05
xdotool type "b"
elif [[ "R" -eq 42 ]]; then
xdotool search --name "WINDOWNAME" windowactivate --sync
sleep .05
xdotool type "n"
elif [[ "R" -eq 43 ]]; then
xdotool search --name "WINDOWNAME" windowactivate --sync
sleep .05
xdotool type "m"
elif [[ "R" -eq 44 ]]; then
xdotool search --name "WINDOWNAME" windowactivate --sync
sleep .05
xdotool type ","
elif [[ "R" -eq 45 ]]; then
xdotool search --name "WINDOWNAME" windowactivate --sync
sleep .05
xdotool type "."
elif [[ "R" -eq 46 ]]; then
xdotool search --name "WINDOWNAME" windowactivate --sync
sleep .05
xdotool type "/"
else
break
fi
done

Antwort1

Allein auf Ihrem Titel basierend ifist eine unendliche Aussage lediglich eine whilemit entsprechend angepasster Logik.

Außerdem ist Ihr Code extrem hektisch und Sie müssen dringend etwas Formatierung verwenden.

Darüber hinaus sollten Sielies deinen Fehler. Es wird deutlich darauf hingewiesen, dass Sie irgendwo eine zusätzliche Klammer haben. Sehen Sie sich also Ihren Code genauer an und experimentieren Sie, um eine Lösung zu finden. Um tatsächlich eine Antwort zu geben, sage ich Ihnen jetzt, dass Sie Ihr „$“ vor den Beginn der Klammern setzen müssen. So funktionieren Variablen nun einmal.

Stellen Sie abschließend sicher, dass Ihr Titel auch in Zukunft für Ihre Frage relevant ist.

verwandte Informationen