如何在 xterm (zsh) 上自动回答“y”或“n”

问题描述 投票:0回答:1

我想做什么?

xterm -e <bunch of commands>

我被困在哪里?
xterm 提示“不安全目录并继续 [y] 或 [n]?”

我想要什么修复?
使用

y
选项回答该提示
return
-e
,以便可以运行其他命令。

P.S.:我知道完全消除提示的修复方法。我只是想知道是否有办法每次都做到这一点

y
return

linux zsh xterm
1个回答
0
投票

最简单的方法是将

echo "y"
通过管道传输到命令。例如

echo "y" | apt upgrade

另一种选择是使用expect。
这是一个最小的示例,您可能需要添加超时、将命令拆分为单独的生成等。

#!/usr/bin/expect

# Spawns your programm
spawn xterm -e <bunch of commands>

# Expected output from the command
expect "Insecure directory and continue"

# Answer the command
send "y\r"

expect eof

生成expect脚本的一个简单方法是手动运行

autoexpect xterm -e <bunch of commands>
,它将生成一个脚本作为script.exp。

© www.soinside.com 2019 - 2024. All rights reserved.