Results 1 to 10 of 11

Thread: 'if' condition to add new PPA always produces a one sided result

Threaded View

  1. #1
    Join Date
    Oct 2011
    Sacramento, California
    Xubuntu 14.04 Trusty Tahr

    Unhappy 'if' condition to add new PPA always produces a one sided result


    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:
    for APT in `find /etc/apt/ -name *.list`; do
        grep -o "^deb[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
    The next part however is the somewhat confusing and a bit frustrating.
    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.
    for PPAx in $MyPPAs; do
        echo "Current ppa to be added is: $PPAx"
        sleep 0.5
        #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
    apt-get update
    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.
    Last edited by octius4u; April 29th, 2014 at 01:17 AM. Reason: apt-get update should have been at the end


Posting Permissions

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