处理 Linux 命令行中安装程序的提示

处理 Linux 命令行中安装程序的提示

我正在编写一个 bash 脚本,除其他功能外,它还安装一些软件。我运行的其中一个安装程序需要回答一些问题。例如:

Is the default install folder ok (yes/no)?
What is the email address you would like to use?

安装程序不提供脚本响应选项。有没有办法在从 bash 脚本运行安装程序时识别这些提示并自动提供响应?例如:

Is the default install folder ok (yes/no)? yes
What is the email address you would like to use? [email protected]

答案1

您想要的工具名为expect

答案2

在某些情况下,您可以使用yes

答案3

您是否尝试过使用像这样的转换语句?

#!/bin/bash

echo -n "Do you agree with this? [yes or no]: "
read yno
case $yno in

        [yY] | [yY][Ee][Ss] )
                echo "Agreed"
                ;;

        [nN] | [n|N][O|o] )
                echo "Not agreed, you can't proceed the installation";
                exit 1
                ;;
        *) echo "Invalid input"
            ;;
esac

$ ./yorno.sh
Do you agree with this? [yes or no]: YES
Agreed

相关内容