AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / server / 问题 / 1053877
Accepted
acgbox
acgbox
Asked: 2021-02-17 11:36:24 +0800 CST2021-02-17 11:36:24 +0800 CST 2021-02-17 11:36:24 +0800 CST

如何使用expect命令和.run程序替换yes命令

  • 772

我正在尝试运行的program.run :

  • 提出 2 个需要回答“y”的问题
  • 最后问第三个问题,即“按任意键退出”

在此处输入图像描述

此外,它没有“-y”选项。只有这个选项:

FreeFileSync installation parameters:
-h, --help    Show help
--directory   Change installation directory e.g. --directory /opt/FFS
--noshortcuts  Don't create desktop shortcuts

这些命令都不起作用:

yes | sudo ./program.run
yes y | sudo ./program.run
sudo sh -c 'yes y | ./program.run'
echo y | sudo ./program.run
# etc, etc

在此处输入图像描述

由于“是”命令似乎不起作用,我想尝试其他任何东西

在这个答案中,说:“.run 命令只是一组将由 sh 运行的命令。特定的 .run 文件可能需要 -y 选项,但通常你不能指望它。如果你需要自动化一些东西,考虑使用Expect "。

但我不知道如何使用Expect。一些帮助?

发行版:Ubuntu Mate 20.04 LTS

Bash 5.0.17(1)-release (x86_64-pc-linux-gnu)

更新:

我已经在官方网站上发布了这个问题,开发人员宣布在下一个版本中他们将添加参数:

./program.run --accept-license
bash command
  • 2 2 个回答
  • 201 Views

2 个回答

  • Voted
  1. Best Answer
    Arkadiusz Drabczyk
    2021-02-17T13:39:37+08:002021-02-17T13:39:37+08:00

    那expect将是:

    #!/usr/bin/expect
    
    set timeout -1
    log_user 0
    spawn ./FreeFileSync_11.6_Install.run
    log_user 1
    
    expect -exact "\r
    Accept the FreeFileSync license terms? (Enter 's' to show them) \[y/n/s\] "
    send -- "y\r"
    expect -exact "y\r
    Install FreeFileSync into /opt/FreeFileSync? \[Y/n\] "
    send -- "Y\r"
    expect -exact "https://freefilesync.org/donate\r
    \r"
    

    跑:

    $ sudo ./expect-script
    [sudo] password for user:
    
    Accept the FreeFileSync license terms? (Enter 's' to show them) [y/n/s] y
    Install FreeFileSync into /opt/FreeFileSync? [Y/n] Y
    
    -> Installing to: /opt/FreeFileSync
    -> New console command: freefilesync
    -> Registering file extensions: *.ffs_gui, *.ffs_batch, *.ffs_real
    
    All done!
    
          (\_/)
      (  =(^Y^)=
       \_(m___m)
    
    Get the Donation Edition with bonus features and help keep FreeFileSync ad-free.
    https://freefilesync.org/donate
    
    • 1
  2. d.c.
    2021-02-17T13:04:22+08:002021-02-17T13:04:22+08:00

    如果我想为以下 3 个问题提供自动答案:

    y<输入>

    y<输入>

    <进入>

    我会使用类似的东西:

    printf "y\ny\n\n" | sudo ./program.run
    
    • 0

相关问题

  • Mac OS X:从 python 脚本中更改 $PATH

  • Bash 脚本:要求脚本以 root 身份运行(或使用 sudo)

  • crontab ifconfig 什么都不输出

  • 使用命令行工具按排序顺序计算重复项

  • 是否有 bash 等效于 ruby​​ 的“一些内容#{foo}”?

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    新安装后 postgres 的默认超级用户用户名/密码是什么?

    • 5 个回答
  • Marko Smith

    SFTP 使用什么端口?

    • 6 个回答
  • Marko Smith

    命令行列出 Windows Active Directory 组中的用户?

    • 9 个回答
  • Marko Smith

    什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同?

    • 3 个回答
  • Marko Smith

    如何确定bash变量是否为空?

    • 15 个回答
  • Martin Hope
    Tom Feiner 如何按大小对 du -h 输出进行排序 2009-02-26 05:42:42 +0800 CST
  • Martin Hope
    Noah Goodrich 什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同? 2009-05-19 18:24:42 +0800 CST
  • Martin Hope
    Brent 如何确定bash变量是否为空? 2009-05-13 09:54:48 +0800 CST
  • Martin Hope
    cletus 您如何找到在 Windows 中打开文件的进程? 2009-05-01 16:47:16 +0800 CST

热门标签

linux nginx windows networking ubuntu domain-name-system amazon-web-services active-directory apache-2.4 ssh

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve