Ubuntu – Auto Passing a “q” before a Y on a command line

bashcommand linescripts

I am trying to download the teamspeak 3 client and accept the license agreement routine all at the same time. I know how to pass a “yes” before the script but the routine requires me to press Q to quit the “license agreement” before clicking the Y key to start the unpacking of the client.

#!/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

As you can see, the routine requires the pressing of Q first. When I press Q, Y is then pressed automatically and the files decompress.

+ 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

Would someone be so kind in showing me the way?

Best Answer

The q keypress serves as a quit signal for the pager less, which is explicitly used by the script:

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

And man less says:

Options are also taken from the environment variable "LESS".

Set this environment variable as follows:

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

Solution taken from @steeldriver's comment and added according to the law of @JamesTheAwesomeDude.

Related Question