Results 1 to 6 of 6

Thread: Alias for adding multiple ppas

  1. #1
    Join Date
    Jul 2011
    Beans
    11

    Alias for adding multiple ppas

    I'm trying to crate an alias, but can't figure out how to make it work. I've tried to add this to bash_aliases, then sourced .bashrc (the part about bash_aliases is already uncommented):

    Code:
    alias addppas="for i in $@; do sudo add-apt-repository -y $1; shift; done"
    I'm not that good whith bash... The idea is that you would be able to type in:

    Code:
    addppas ppa1 ppa2 ...
    and it would add them all.

    Thanks in advance, reference to info is also welcome
    Last edited by ferhtgoldaraz; October 25th, 2012 at 11:50 PM.

  2. #2
    Join Date
    Jul 2011
    Beans
    11

    Re: Alias for adding multiple ppas

    Since bash outputs:

    Code:
    bash: syntax error near unexpected token `ppa:ubuntu-wine/ppa'
    I thought maybe changing $1 to '$1'... Didn't help anything.

    I forgot to say this is ubuntu 12.10 x64 in a pretty normal acer.

  3. #3
    Join Date
    Jul 2011
    Beans
    11

    Re: Alias for adding multiple ppas

    I've found out that the position parameters get interpeted when creating the alias, rather than during it's execution, and that I should instead use a function. So I wrote this in .bashrc:

    Code:
    # My functions
    function addppas() {
      for i in $@
      do
        sudo add-apt-repository -y $1
        shift
      done
    }
    And it doesn't work, but now bash says:
    Code:
    bash: syntax error near unexpected token `&'
    What?

  4. #4
    Join Date
    Jul 2011
    Beans
    11

    Re: Alias for adding multiple ppas

    I had to close the terminal and reopen it. Some failed attempt of function must have been recorded in that environment.

    If any one is interested, here is the working function:

    Code:
    addppas ()
    {
      for i in $@
      do
        sudo add-apt-repository -y $1
        shift
      done
      sudo apt-get update
    }
    And here are some aliases:

    Code:
    alias addppa="sudo add-apt-repository"
    alias aptinstall="sudo apt-get install"
    alias aptupgrade="sudo apt-get upgrade"
    alias aptautoremove="sudo apt-get autoremove"
    alias aptupdate="sudo apt-get update"
    You can copy-paste the function at the end of .bashrc (It's in your home folder, as a hidden file. Run gedit .bashrc from a new terminal, or better yet hit Ctrl + F2 and type it in).

    As for the aliases, Ctrl + F2...

    Code:
    gedit .bash_aliases
    Copy-paste them as above, and save. That will let you type in those short words instead of the tedious ones that are between ""s

    Self-responded at the end

    Hope somebody finds this at least a bit useful
    Last edited by ferhtgoldaraz; October 26th, 2012 at 01:54 AM.

  5. #5
    Join Date
    Jul 2007
    Location
    Poland
    Beans
    4,499
    Distro
    Ubuntu 14.04 Trusty Tahr

    Re: Alias for adding multiple ppas

    why do you use for loop and shift together? loop will go through all the values either way, you don't need to help it by pushing parameters to the front
    Code:
    for i; do sudo add-apt-repository -y $i; done
    is enough
    if your question is answered, mark the thread as [SOLVED]. Thx.
    To post code or command output, use [code] tags.
    Check your bash script here // BashFAQ // BashPitfalls

  6. #6
    Join Date
    Jul 2011
    Beans
    11

    Re: Alias for adding multiple ppas

    Wow, thanks. I don't know almost anything about bash.

    Much better!

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •