在命令行上,在 Y 之前自动传递“q”

在命令行上,在 Y 之前自动传递“q”

我正在尝试同时下载teamspeak 3客户端并接受许可协议例程。我知道如何在脚本前输入“是”,但例程要求我先按Q退出“许可协议”,然后再单击Y开始解压客户端的键。

#!/bin/bash
cd /home/test/ts3_client_files
wget http://dl.4players.de/ts/releases/3.0.19.4/TeamSpeak3-Client-linux_amd64-3.0.19.4.run
yes 'y' | ./TeamSpeak3-Client-linux_amd64-3.0.19.4.run

如您所见,该例程要求先按下Q。当我按下 时QY然后自动按下 ,文件就会解压缩。

+ cd /home/test/ts3_client_files
+ wget http://dl.4players.de/ts/releases/3.0.19.4/TeamSpeak3-Client-linux_amd64-3.0.19.4.run
--2016-09-05 08:33:26--  http://dl.4players.de/ts/releases/3.0.19.4/TeamSpeak3-Client-linux_amd64-3.0.19.4.run
Resolving dl.4players.de (dl.4players.de)... 85.25.26.25, 85.25.26.26, 85.25.26.27
Connecting to dl.4players.de (dl.4players.de)|85.25.26.25|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 37054436 (35M) [application/x-makeself]
Saving to: ‘TeamSpeak3-Client-linux_amd64-3.0.19.4.run’

100%[=============================>] 37,054,436  9.56MB/s   in 7.1s

2016-09-05 08:33:34 (4.96 MB/s) - ‘TeamSpeak3-Client-linux_amd64-3.0.19.4.run’ saved [37054436/37054436]

+ chmod 0700 TeamSpeak3-Client-linux_amd64-3.0.19.4.run
+ yes y
+ ./TeamSpeak3-Client-linux_amd64-3.0.19.4.run
Welcome to the TeamSpeak 3 Client for Linux on amd64 installer

In order to install this software you are required to accept the license
agreement, please press return to view the license.

You can scroll with the arrow keys and quit the viewer by pressing 'q'.
[RETURN]
Please type y to accept, n otherwise: Creating directory TeamSpeak3-Client-linux_amd64
Verifying archive integrity... All good.
Uncompressing TeamSpeak 3 Client for Linux on amd64  100%
+ exit

有人能好心地给我指条路吗?

答案1

q按键充当分页器的退出信号less,脚本明确使用了该信号:

read FOO
echo "$licensetxt" | less
while true
do
  MS_Printf "Please type y to accept, n otherwise: "
  read yn
  if test x"$yn" = xn; then
    keep=n
eval $finish; exit 1
    break;
  elif test x"$yn" = xy; then
    break;
  fi
done

man less说:

选项也取自环境变量“LESS”。

按如下方式设置此环境变量:

printf '\ny\n' | LESS='+q' ./TeamSpeak3-Client-linux_amd64-3.0.19.4.run

解决方案取自@steeldriver 的评论并根据添加@JamesTheAwesomeDude 的法律

相关内容