Como eu faço um loop de script de shell através de múltiplas instruções if para sempre?

-1

Eu fiz um script baseado em um monte de trechos e tutoriais que eu li. Eu simplesmente não consigo descobrir como corrigir um erro de sintaxe e fazê-lo funcionar. Saída de terminal é:

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

Pelo que li nos tutoriais, esses colchetes são necessários. Aqui está o meu script (com o nome da janela substituído):

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
    
por OccultusOpus 24.06.2017 / 19:42

1 resposta

0

Com base apenas em seu título, uma instrução if infinita é apenas um while com a lógica ajustada de acordo.

Além disso, seu código é extremamente agitado e você precisa usar urgentemente alguma formatação.

Além disso, você deve ler seu erro . Ele afirma claramente que você tem parênteses extras em algum lugar, então dê uma olhada melhor em seu código e experimente encontrar uma solução. Para realmente fornecer uma resposta, direi agora que você precisa mover seu '$' antes de os parênteses começarem. É assim que as variáveis funcionam.

Por fim, verifique se seu título é relevante para sua pergunta no futuro.

    
por pwfihscjmwe 24.06.2017 / 19:54