
我根據我讀過的一堆程式碼片段和教學製作了一個 shell 腳本。我只是不知道如何修復語法錯誤並使其工作。終端輸出為:
./afkscript.sh: 2 ./afkscript.sh: Syntax error: "(" unexpected ( expecting "done")
根據我在教程中讀到的內容,這些括號是需要的。這是我的腳本(替換了視窗名稱):
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
答案1
僅根據您的標題,無限if
陳述只是while
相應調整邏輯的。
此外,您的程式碼非常繁忙,您迫切需要使用一些格式。
除此之外你應該閱讀你的錯誤。它清楚地表明您在某處有額外的括號,因此請更好地查看您的程式碼並進行實驗以找到解決方案。為了真正提供答案,我現在告訴您,您需要在括號開始之前移動“$”。這就是變數的工作原理。
最後,確保您的標題與您將來的問題相關。