1

How can I send the Return key in a script file? I am installing all the PPAs from a script, and while it works, currently the addition of each PPA requires user input of the carriage return.

#!/bin/bash
add-apt-repository ppa:yannubuntu/boot-repair

add-apt-repository ppa:libreoffice/libreoffice-5-1
0

2 Answers 2

1

In this particular case, you want the -y flag added. From man add-apt-repository:

-y, --yes Assume yes to all queries

0

The comment by kos is correct, this is more or less answered at Auto confirm when running bash scripts.

Serg has the right idea forget about passing a carriage return and just pass -y to add-apt-repository. Just use his answer.

-y, --yes Assume yes to all queries

So your script would look like such;

#!/bin/bash
add-apt-repository -y ppa:yannubuntu/boot-repair

add-apt-repository -y ppa:libreoffice/libreoffice-5-1

Carriage Returns from Shell

Just to clarify how to send a carriage return from a script, there are a lot of options actually.

You could use the yes command which was built to output y along with a newline or an optional argument with newline. Thus, yes with no argument is a carriage return. You can pass a carriage return in a script with the commands from your example;

#!/bin/bash
yes '' | add-apt-repository ppa:yannubuntu/boot-repair

yes '' | add-apt-repository ppa:libreoffice/libreoffice-5-1

I think echo would work too actually if it's passing a new line, again from your example;

#!/bin/bash
echo | add-apt-repository ppa:yannubuntu/boot-repair

echo | add-apt-repository ppa:libreoffice/libreoffice-5-1

Or for more complicated variations you could use expect even.

Not the answer you're looking for? Browse other questions tagged .