非交互式安装Miniconda2

时间:2017-07-08 04:33:36

标签: bash scripting expect

是否可以按顺序向安装脚本发送多个响应?具体来说,如果安装脚本要求您按enter,然后按Q,再按yes,就像在此帖子中所示: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 script

3 个答案:

答案 0 :(得分:1)

您正在寻找expect

  

Expect是一个根据脚本与其他交互式程序“对话”的程序。在脚本之后,Expect知道程序可以期待什么以及正确的响应应该是什么。解释语言提供分支和高级控制结构来指导对话。此外,用户可以在需要时直接进行控制和交互,然后将控制权返回给脚本。

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

答案 1 :(得分:0)

对于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和/或-u)。

答案 2 :(得分:0)

这不需要任何手动干预

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

相关问题