0

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
1
  • Please take a look: shellcheck.net Commented Oct 31, 2017 at 7:30

2 Answers 2

1

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
Sign up to request clarification or add additional context in comments.

3 Comments

also if its not too much to ask, im getting a error again, this is it: ./admin2.sh: line 232: unexpected EOF while looking for matching `"' this is what is on line 232: echo -e "${LIGHTRED} Done!"
also error: ./admin2.sh: line 240: syntax error: unexpected end of file and this is what is on line 239: esac nothing is on line 240 the script ends on line 239
Sounds like you are missing a " somewhere, you probably started a string somewhere and forgot to end it
0

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.