以非交互方式安装 Miniconda2

Installing Miniconda2 Non-Interactively

是否可以按顺序向安装脚本发送多个响应?具体来说,如果安装脚本要您按 enter,然后按 Q,然后按 yes,例如 post:install miniconda.

我试过将东西放在一起,但由于我对 bash 脚本编写非常不熟悉,我可能只是搞砸了或者采用了错误的方法。


编辑:

我尝试编写一个 expect 脚本,但它挂起,如下图所示。

#!/usr/bin/expect -f
spawn ~/Miniconda-latest-Linux-x86_64.sh
set timeout -1
expect "$ "
send "\r"
expect "Welcome "
send "Q"
expect "? "
send "yes"

您正在寻找 expect:

Expect is a program that "talks" to other interactive programs according to a script. Following the script, Expect knows what can be expected from a program and what the correct response should be. An interpreted language provides branching and high-level control structures to direct the dialogue. In addition, the user can take control and interact directly when desired, afterward returning control to the script.


编辑: 查看屏幕截图,它要求您 "press ENTER to continue" 我在您的脚本中没有看到。您有 send "\r" 但这通常不是 Enter 发送的内容。在 Windows 上它会发送 /r/n,在 Linux 上它会发送 /n。试一试。

对于 miniconda3,尝试命令行标志:

bash-4.2# curl -s -L -o miniconda_installer.sh \
          https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh

bash-4.2# bash miniconda_installer.sh -h

usage: miniconda_installer.sh [options]

Installs Miniconda3 4.7.10

-b           run install in batch mode (without manual intervention),
             it is expected the license terms are agreed upon
-f           no error if install prefix already exists
-h           print this help message and exit
-p PREFIX    install prefix, defaults to /root/miniconda3, must not contain spaces.
-s           skip running pre/post-link/install scripts
-u           update an existing installation
-t           run package tests after installation (may install conda-build)

因此 -b 选项可能有所帮助(可能还需要 -f and/or -u)。

这不需要任何人工干预

>curl "https://repo.continuum.io/miniconda/Miniconda-latest-MacOSX-x86_64.sh" -o miniconda_installer.sh 
>bash miniconda_installer.sh -b -f -p $InstallDirectory