0
votes

I need an important help with my bash code, I have been in this state like this for 1 hour and I did not get anywhere, I solved the end of code error, but now I am in that and I am not able to advance, prove changing elif by else if but still I did not find a solution help! Thanks.

Error code: line 39 (19 after edit): syntax error near unexpected token `elif'

echo -e '\e[31m[ 1 ] Instalar paquetes\e[1m'
sleep 0.1
echo -e '\e[31m[ 2 ] Instalar Herramientas\e[1m'
sleep 0.1
echo -e '\e[31m[ 3 ] Eliminar Herramienta\e[1m'
sleep 0.1
echo -e '\e[31m[ 4 ] Info\e[1m'
sleep 0.1
echo -e '\e[31m[ 5 ] Salir\e[1m'
sleep 0.1
echo ' '

echo -e '\e[34mInserte la opción que desea utilizar:'
read vw
if [ $vw = 1 ];
then
    sleep 1.3
    echo 'Inserte el nombre del paquete que desea instalar ej.python'
    read instalar
    pkg install $instalar
elif [ $vw = 2 ];
then
    sleep 1.3
    bash tools.sh
fi
elif [ $vw = 3 ];
then
    sleep 1.3
    echo  'inserte el nombre de la herramienta que desea eliminar:'
    read eliminar
    rm -rf $eliminar
fi
elif [ $vw = 4 ];
then
    sleep 1.3
    echo 'Autor: '
fi
elif [ $vw = 5];
then
    sleep 1.3
fi
else
    echo 'Por favor inserte un numero del que se encuentra en la lista'
    sleep 4
    bash chesthacker.sh
    exit 0
fi
1
Please don't post double-spaced code. - Barmar
Get rid of all the fi before elif and else. - Barmar
You only need one fi keyword at the end of the if/elif/else chain, not after each block. - Barmar
And post code to ShellCheck to identify errors, then post remaining issues here. - David C. Rankin
There's also no need for ; at the end of lines, but it's merely redundant, not an error. - Barmar

1 Answers

1
votes
fi
elif [ $vw = 3 ];

This is incorrect, If you finished if block with fi, you can't start new block with elif. The correct syntax is:

if ...
then 
elif ..
then 
elif ...
then
else
fi