I trying to write a bash script to add ppas and then run apt-get update .
How ever I'd like the new ppa to added only after a list of existing ppa's has been made.
In oder to check if the new ppas are not already installed.
This first part of code I found a while ago on a ubuntu forum I believe,
and it was very instructional and works properly.
The first part is:
The next part however is the somewhat confusing and a bit frustrating.
for APT in `find /etc/apt/ -name *.list`; do
grep -o "^deb http://ppa.launchpad.net/[a-z0-9\-]\+/[a-z0-9\-]\+" $APT | while read ENTRY ; do
USER=`echo $ENTRY | cut -d/ -f4`
PPA=`echo $ENTRY | cut -d/ -f5`
echo "$PPAlink" >> $ExistingPPAs
cat $ExistingPPAs ## For my own testing purposes to verify content
Here I am trying to add the new PPA from a list in $MyPPAs, but only if $?, the result from grep is not 0.
The problem is the that if condition finds all results to be 0 even the echo above shows them to be 1.
So basically whether PPAx exists in the tempfile or not all are found to be existing.
PLEASE HELP. I have searched for help with if condition inside for do loops but I can't find any solution after hours of trying.
for PPAx in $MyPPAs; do
echo "Current ppa to be added is: $PPAx"
#GrepResult=$(grep -oqs $PPAx $ExistingPPAs) ## I considered using a variable but the produced even more problems.
grep -oqs $PPAx $ExistingPPAs
echo "grep sais: $?" #check the correct respons is given, and it always is correct.
if [ "$?" == "0" ]; then
echo "*** $PPAx has been FOUND and will be skipped."
echo "*** $PPAx does currently NOT exist."
add-apt-repository -y $PPAx