I executed the following command to add a ppa repository in Ubuntu:sudo add-apt-repository ppa:ppaname/ppaThis command returned an error that the ppa name format is not correct. Then I looked here and thus, ran the follwing command:sudo -E add-apt-repository ppa:ppaname/ppaThe above command worked like magic. Then I read the man page for sudo which said that sudo -E preserves environment variables. What I do not understand is how preserving the environment variables helped me here?Note: I am working behind a proxy.
How does sudo -E work here?
ubuntu;sudo;environment variables;repository;ppa
If you use proxy to make internet connection, maybe your system set some environment variable for your user to set the proxy server IP. When you use sudo without -E option, your environment variables are not preserved, so you can't connect to internet, causing add-apt-repository show that error. Checking add-apt-repository source code, you can see:try:    ppa_info = get_ppa_info_from_lp(user, ppa_name)except HTTPError:    print _(Cannot add PPA: '%s'.) % line    if user.startswith(~):        print _(Did you mean 'ppa:%s/%s' ? %(user[1:], ppa_name))        sys.exit(1) # Exit because the user cannot be correct    # If the PPA does not exist, then try to find if the user/team     # exists. If it exists, list down the PPAs    _maybe_suggest_ppa_name_based_on_user(user)    sys.exit(1)So if you can not connect to internet, _maybe_suggest_ppa_name_based_on_user() will be called. And here's its implementation:def _maybe_suggest_ppa_name_based_on_user(user):    try:        from launchpadlib.launchpad import Launchpad        lp = Launchpad.login_anonymously(lp_application_name, production)        try:            user_inst = lp.people[user]            entity_name = team if user_inst.is_team else user            if len(user_inst.ppas) > 0:                print _(The %s named '%s' has no PPA named '%s'                         %(entity_name, user, ppa_name))                print _(Please choose from the following available PPAs:)                for ppa in user_inst.ppas:                    print _( * '%s':  %s %(ppa.name, ppa.displayname))            else:                print _(The %s named '%s' does not have any PPA                        %(entity_name, user))        except KeyError:            pass    except ImportError:        print _(Please check that the PPA name or format is correct.)You can see, it will show the message Please check that the PPA name or format is correct if it can not import Launchpad. You need to install python-launchpadlib to make the import successful.NoteI think it's ambiguous to report that message, since when the launchpadlib also need internet connection to work. In this case, the script should check weather the internet connection is down or not to report more clearly.