Shell script to skip PPA if installed

That is a bash function, and to pass arguments to bash functions, you don't need (). Also, the function adds the ppa: prefix to its arguments, so just this would do:

add_ppa otto-kesselgulasch/gimp-edge

Additionally, the function supports multiple arguments, so you can run it for multiple PPAs:

add_ppa otto-kesselgulasch/gimp-edge foo/bar a/b

Given that you have put the function in a script, you should either:

  • source it as Zanna suggests to get the function in your shell and call the function, or
  • just use the contents of the function as the script:

    #! /bin/bash
    for i in "$@"; do
      if grep -Rq "^deb.*$i" /etc/apt/sources.list.d/*.list
      then
        echo "Adding ppa:$i"
        sudo add-apt-repository -y ppa:$i
      else
        echo "ppa:$i already exists"
      fi
    done
    

    And the call the script with the ppa name:

    ppa otto-kesselgulasch/gimp-edge
    

I think you are executing the file as a script, but it's only a function definition, so the function is never called when it's run.

You don't need to add anything to it; you don't need to add the PPA anywhere inside it. You can source the file and then call the function in the current shell:

. ppa
add_ppa otto-kesselgulasch/gimp-edge

(assuming the file you saved it in is called ppa, is in the current working directory, and has exactly the same content as the example you posted)

You could also run it as a script, if you add a line that actually calls the function. You could hard-code the PPA into it by adding a line like this at the end:

add_ppa otto-kesselgulasch/gimp-edge

and then run the script. But that way, you'd have to edit the file every time you wanted to add a new PPA...

Instead you can call the function on all the arguments passed to the script by adding a line like this:

add_ppa "$@"

then when the script is called:

./ppa otto-kesselgulasch/gimp-edge thing/stuff etc/andSoOn