Tuesday, May 2, 2017

bash - Shell script to skip PPA if installed

I would like to create a script that will add a new PPA or skip if already installed.



Someone posted this solution to a different question:



#!/bin/bash 

add_ppa() {
for i in "$@"; do
grep -h "^deb.*$i" /etc/apt/sources.list.d/* > /dev/null 2>&1

if [ $? -ne 0 ]
then
echo "Adding ppa:$i"
sudo add-apt-repository -y ppa:$i
else
echo "ppa:$i already exists"
fi
done
}



shell script to conditionally add apt repository



In my case I would like to add ppa:otto-kesselgulasch/gimp-edge, but I am not sure where I am supposed to add this in the script.



I tried add_ppa(ppa:otto-kesselgulasch/gimp-edge) but I keep getting an error saying (ppa is the name of my script):



ppa: 1: ppa: Syntax error: word unexpected (expecting ")")



I also tried with a space in between ppa and without the ()



ppa: 1: ppa: add_ppa: not found
ppa: 12: ppa: Syntax error: "}" unexpected


Can anyone tell me what am I doing wrong please?

No comments:

Post a Comment

11.10 - Can't boot from USB after installing Ubuntu

I bought a Samsung series 5 notebook and a very strange thing happened: I installed Ubuntu 11.10 from a usb pen drive but when I restarted (...