EndzoW
EndzoW

Reputation: 11

getting error when running my bash script

I made this bash script but getting this error when running it: ./admin2.sh: line 78: syntax error near unexpected token else' ./admin2.sh: line 78:else'. I've edited it many times but i cant seem to find what exactly the error is. this is the script:

#!/bin/bash
if [[ $key == 1029127 ]]
clear
echo -e ""
echo -e -n "${LIGHTRED}[!] ${WHITE}Loading admin menu"
spinner () {
local SP_WIDTH="$3"
local SP_DELAY="$4"
local SP_STRING=${2:-"'|/=\'"}
local SP_COLOR=0
tput civis
while [ -d /proc/$1 ]; do
    ((RANDOM%2 == 0)) && SP_COLOR=3$((RANDOM%8)) ||
SP_COLOR=9$((RANDOM%8))
    printf "\e[1;${SP_COLOR}m\e7  %${SP_WIDTH}s  \e8\e[0m" "$SP_STRING"
    sleep ${SP_DELAY:-.2}
    SP_STRING=${SP_STRING#"${SP_STRING%?}"}${SP_STRING%?}
done
tput cnorm
}

sleep 2.5 &
spinner "$!" '-\\|/' '1.1' '.2'
tput civis
sleep 1
tput cnorm
while true
do
clear
echo -e "${LIGHTCYAN} Welcome"
echo -e ""
echo -e -n "${WHITE}- Current IP:${LIGHTRED} "
w|awk '{if(NR>2){print $3}}' $3
echo -e -n "${WHITE}- Users connected:${LIGHTRED} "
users | wc -w
echo -e "${WHITE}- Admin privileges:${WHITE
[${LIGHTGREEN}Enabled${WHITE}]"
echo -e ""
echo -e "${LIGHTRED} //Announcements//"
echo -e ""
echo -e "${YELLOW}- Type: /help to see commands"
echo -e "\n"
echo -e ""
echo -e ""
echo -e -n "${LIGHTRED}Type: \c"
read answer
else
echo -e ""
echo -e "${LIGHTRED}[!] ${WHITE}Incorrect key, access denied.
fi

Upvotes: 0

Views: 53

Answers (2)

Svomp
Svomp

Reputation: 184

You also seem to have forgotten to end the second while loop. You should end it by adding a doneon the line before the else

...
read answer
done
else
  echo -e ""
  echo -e "${LIGHTRED}[!] ${WHITE}Incorrect key, access denied.
fi

Upvotes: 1

dimo414
dimo414

Reputation: 48794

You're missing a then after your if statement on line 2:

if [[ $key == 1029127 ]]
then
  ...
else
  ...
fi

Many people prefer to put the then on the same line, as:

if [[ $key == 1029127 ]]; then
  ...
else
  ...
fi

Either way I'd encourage you to properly indent your code so that it's easier to read, and be consistent about style choices such as putting then and do on separate lines or not.

Upvotes: 0

Related Questions