LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (http://www.linuxquestions.org/questions/programming-9/)
-   -   Syntax error near unexpected token ';;' (http://www.linuxquestions.org/questions/programming-9/syntax-error-near-unexpected-token-%3B%3B-4175423928/)

Vashezz 08-25-2012 07:36 AM

Syntax error near unexpected token ';;'
 
Code:

#!/usr/local/bin/bash
RSA_keys ()
{
echo "making folder rsakeys in /usr/home/"
if [ ! -d $HOME/rsakeys ]; then
cd $HOME
mkdir rsakeys
else
# rest code
fi
}
# Check openSSL
if [ ! -x "/usr/local/bin/openssl" ]; then
#
        echo -e "\033[1;31m OpenSSL not found!\033[0m"
        echo -e "\033[1;36m do you want install OpenSSL?\n\033[0m
        1 - yes\n
        2 - no"
                read odp
                case $odp in
                1*)
                        cd /usr/ports/security/openssl
                        make install clean
                        RSA_keys()
                ;; #here ive got error with ";;"
                2*)
                        echo -e "...!"
                ;;
                esac
       
else
echo "Script starting"
RSA_keys()
fi

When i tiring execute this script, ive recive message "rsagen.sh: line 25: syntax error near unexpected token ';;'"
rsagen.sh: line 25: ' ;;'
Maybe something in function is wrong and by this ive got eror in case?

unSpawn 08-25-2012 08:45 AM

Easiest way is to "set -vx" beforehand and watch where it goes belly up but once defined you don't use parenthesis anymore and in case statements you only use wildcards if really necessary. BTW could this be a more logical flow:
Code:

RSA_keys() {
 echo "making folder rsakeys in ${HOME}/rsakeys"
 [ -d "$HOME/rsakeys" ] || { mkdir "$HOME/rsakeys" || exit 1; }
} # End RSA_keys

installSSL() {
 echo -en "OpenSSL not found. Install? [Y|n] "; read ANSWER
 case "$ANSWER" in
  Y|y) cd /usr/ports/security/openssl && make install clean && RSA_keys;;
  N|n) echo "OK, exiting"; exit 127;;
  *) echo "Ze monkey pressing ze vrong buttonz."; exit 1;;
esac
} # End installSSL

# Start by checking OpenSSL installation
HAS_OPENSSL=1
for ITEM in ${PATH//:/ }; do
 [ -x "${ITEM}/openssl" ] && HAS_OPENSSL=0
done; [ $HAS_OPENSSL -ne 0 ] && installSSL

echo "Script starting"
RSA_keys



All times are GMT -5. The time now is 10:20 PM.