70

Basically, I want to run add-apt-repository ppa:(whatever) without the "press Enter to continue" prompt. How would I do this?

Essentially, I want to deploy adding a repository in a shell script without user input.

  • 13
    Just add -y at the end of the command add-apt-repository -y .... – Uri Herrera Jun 5 '13 at 0:25
  • 1
    man add-apt-repository and you will see the -y switch that @UriHerrera said. – NickTux Jun 5 '13 at 1:33
95

The script goes like this

#! /bin/sh
sudo add-apt-repository ppa:(Your ppa here) -y

BTW you will still have to enter password.

| improve this answer | |
  • what error are you getting? – Registered User Feb 21 '14 at 10:05
  • 1
    aditya, you man Its Working :D , just now checked... – Babin Lonston Feb 21 '14 at 10:07
  • 1
    You should run the script as root, so you don't need sudo and thus no password – rubo77 Nov 26 '19 at 21:01
-2

Of course if you really want to impress R2D2, you can avoid the password prompt as well. Prepare your user account to look like this:

you@yourhost:~$
you@yourhost:~$ cat /home/you/.bash_login;
# ASK_PASS service for you «begins»
export SUDO_ASKPASS="/home/you/.ssh/.supwd.sh";
# ASK_PASS service for you «ends»
you@yourhost:~$
you@yourhost:~$
you@yourhost:~$ cat /home/you/.ssh/.supwd.sh;
#!/bin/sh
echo '(Your sudoer password here)';
you@yourhost:~$
you@yourhost:~$
you@yourhost:~$ ls -l .ssh/.supwd.sh 
-rwx------ 1 you you 35 Mar 31 10:28 .ssh/.supwd.sh
you@yourhost:~$ 
you@yourhost:~$
you@yourhost:~$ cat ./tmp.sh 
#!/bin/sh
. /home/you/.bash_login;  # 'source' bash_login to declare the ask_pass script
sudo -A add-apt-repository ppa:(Your ppa here) -y;
# The flag '-A' lets you add the repo without sudo demanding your password.
#
you@yourhost:~$
| improve this answer | |
  • 1
    Down voting without explanation should not be permitted. The OP said, "... I want to deploy adding a repository in a shell script without user input." Typing a password for sudo is user input. There's NO reason to downvote this. Doing so is just random malice. – Martin Bramwell Aug 13 at 13:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.