linuxnoob
linuxnoob

Reputation: 685

Is there a way to automate the return key after a linux script command?

I am using the line below in my script add-apt-repository ppa:webupd8team/java When it is run from the script I get a prompt to press [return] to confirm adding the source to the repositories

Can I automate that return?

Secondly, I am installing oracle-java7-installer and there is a license agreement that prompts for the user to: 1.. OK the License agreement 2.. select YES to Accept License Terms

Can I automate the OK and automate the keypad left & OK to Accept License Terms? This script is for testing locally and I do want the script to pause for these user inputs each time.

I have seen this method of piping YES to a command: yes | <command here>

I am hoping there is a similar method to automate these steps...

Upvotes: 6

Views: 376

Answers (2)

Ross
Ross

Reputation: 242

For add-apt-repository you can use the -y flag to skip the yes/no prompt.

The Oracle Java one is a little more complicated, but this will do what you want:

echo debconf shared/accepted-oracle-license-v1-1 select true | sudo debconf-set-selections
echo debconf shared/accepted-oracle-license-v1-1 seen true | sudo debconf-set-selections

# Install required packages
sudo apt-get install oracle-java7-installer -y

Upvotes: 2

user2588667
user2588667

Reputation: 510

The command echo will produce a new line!

Upvotes: 0

Related Questions