如何在mysql-server安装过程中确认apt-get确认


1

我正在尝试编写将安装mysql-server-5.6的bash脚本 我想问用户密码然后我将在安装mysql-server和其他一些配置时使用它。

但我的脚本不起作用

#!/bin/bash
mysql_pass="pass"
mysql_pass_again="wrong pass"
while [ "$mysql_pass" != "$mysql_pass_again" ]
do
    read -s -p "Choose mysql root password: " mysql_pass
    echo -e "\n"
    read -s -p "Repeat mysql root password: " mysql_pass_again

    if [ "$mysql_pass" != "$mysql_pass_again" ]; then
        echo -e "\nPasswords do not match!"
    fi
done

echo -e "\nConfiguring mysql."

sudo debconf-set-selections <<< 'mysql-server-5.6 mysql-server/root_password password $mysql_pass'
sudo debconf-set-selections <<< 'mysql-server-5.6 mysql-server/root_password_again password $mysql_pass_again'
sudo apt-get -y --force-yes install mysql-server-5.6 >/dev/null

输入密码后,没有任何事情发生。当我删除&gt; / dev / null然后我可以看到mysql安装程序通知我密码不正确我需要按OK

但是,如果我回显密码是相同的,并且当安装结束时,我能够使用我在安装期间输入的密码连接到mysql-server。

我怎么能告诉apt-get为我按OK? 谢谢

Answers:


0

问题是单引号内的变量:

sudo debconf-set-selections <<< 'mysql-server-5.6 mysql-server/root_password password $mysql_pass'
sudo debconf-set-selections <<< 'mysql-server-5.6 mysql-server/root_password_again password $mysql_pass_again'

当我把它更改为双引号“”它正在工作......

By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.