下面的代码是我正在编写的一个更长的脚本的一部分,它可以帮助在新服务器上自动执行一些系统管理任务,但是我似乎无法让这个IF语句的逻辑工作。
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
........
一旦用户输入Y并点击enter,它就应该使用apt get执行语句,但只是不执行任何操作,继续执行脚本的其余部分,而不会抛出任何错误。
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.
知道为什么吗?
最佳答案
我建议删除read的选项-p
或添加文本:
read -r -p "foo" answer
见:
help read
关于bash - Bash if语句,是/否,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/43701305/