samedi 29 avril 2017

BASH IF statement with Y/N

I have this code below which is part of a much longer script I'm working on to help automate some sysadmin tasks on fresh servers but I can't seem to get the logic working for this IF statement.

apt-get -y install ${CORE_TOOLS[*]}

printf "\nWould you like to install some \033[0;32moptional\033[0m tools in addition to the core build toolkit? [Y/N]\n"
read -r -p answer
if [[ $answer = "Y" ]] ; then
    apt-get -y install ${EXTRA_TOOLS[*]}
fi

........

Once the user types Y and hits enter it's supposed to execute the statement with apt-get, but simply does nothing and continues to execute the rest of the script without throwing any errors.

Processing triggers for ca-certificates (20141019+deb8u2) ...
Updating certificates in /etc/ssl/certs... 174 added, 0 removed; done.
Running hooks in /etc/ca-certificates/update.d....done.

Would you like to install some optional tools in addition to the core build toolkit? [Y/N]
answerY
Cloning into 'testcookie-nginx-module'...
remote: Counting objects: 294, done.
remote: Total 294 (delta 0), reused 0 (delta 0), pack-reused 294
Receiving objects: 100% (294/294), 253.53 KiB | 0 bytes/s, done.

Any idea why this might be?

Aucun commentaire:

Enregistrer un commentaire