Professional Web Applications Themes

Scripting oddness (sh) - FreeBSD

I've been working on a script, and am having a bit of trouble producing reasonable output. First, the script removes all leaf packages that are not listed in a configuration file and are not required by any of those packages, or by any package that those packages require, etc. The problem is that when all currently installed packages are listed as 'do not remove', then the script does not produce the "No packages/ports to remove." output unless line 58 (the line that consists of the command 'true') is uncommented. If that line is commented out, or removed, then no output ...

  1. #1

    Default Scripting oddness (sh)

    I've been working on a script, and am having a bit of trouble producing
    reasonable output. First, the script removes all leaf packages that are
    not listed in a configuration file and are not required by any of those
    packages, or by any package that those packages require, etc.

    The problem is that when all currently installed packages are listed as
    'do not remove', then the script does not produce the "No packages/ports
    to remove." output unless line 58 (the line that consists of the command
    'true') is uncommented. If that line is commented out, or removed, then
    no output is produced.

    Anyone have any ideas on how to troubleshoot?

    Regards,
    --
    dave [ please don't CC me ]
    David Guest

  2. #2

    Default Re: Scripting oddness (sh)

    * David J. Weller-Fahy <com> [2005-03-23 20:36 +0100]: 

    It helps if I include the script.

    Regards,
    --
    dave [ please don't CC me ]


    David Guest

  3. #3

    Default Re: Scripting oddness (sh)

    David J. Weller-Fahy wrote:
     
    >
    >It helps if I include the script.
    >[/ref]
    Bonus points if you inline the relevant portion, or at least name your
    attachment something like foo.sh.

    -d
    Danny Guest

  4. #4

    Default Re: Scripting oddness (sh)

    * Danny Howard <com> [2005-03-23 23:29 +0100]: 

    And, as pointed out - apparently that didn't work either.

    Here's the relevant portion of the script (I'll include only the
    function that seems to be causing the trouble):

    #v+
    list_not_required_by()
    {
    PKGLIST=""

    for PKG in $ ; do
    if [ -s $PKGDB/$PKG/+REQUIRED_BY ] ; then
    # grab list of packages this package is required by
    RB_LIST=`cat $PKGDB/$PKG/+REQUIRED_BY`
    RB_TEMP=$RB_LIST
    for RB in $RB_LIST ; do
    for RM_PKG in $ ; do
    if [ "$RB" = "$RM_PKG" ] ; then
    RB_TEMP=`echo $RB_TEMP | sed "s/$RM_PKG[^ ]*//g"`
    break
    fi
    done
    done
    [ -z "$RB_TEMP" ] && PKGLIST="$PKGLIST $PKG"
    else
    PKGLIST="$PKGLIST $PKG"
    fi
    done
    # true
    }
    #v-

    The line consisting of '# true' seems to be the clincher, as
    mentioned in the previous email. I'm also attaching the rm_leaf.sh file
    renamed to foo.txt.

    Thanks for the hint, Danny.

    Regards,
    --
    dave [ please don't CC me ]


    David Guest

  5. #5

    Default Re: Scripting oddness (sh) - SOLVED (kind of)

    After some experimenting I believe that I've discovered how to fix the
    problem, and the reason for it - I'd been thinking of the '&&' shortcut
    as functionally identical to the if-then-fi construct. That's obviously
    (now ;) not the case. If, as in the previous message, the following
    '&&' shortcut is used:

    #v+
    [ -z "$RB_TEMP" ] && PKGLIST="$PKGLIST $PKG"
    #v-

    Then, if RB_TEMP is not of zero length, the exit status of that command
    is one. Since that command is the last performed in the
    list_required_by function, the exit status of the function is one.
    Because I used 'set -e' at the top of the script, any command (a
    function being a complex command) that exits with a value of one halts
    the execution of the script. However, if we change that line to:

    #v+
    if [ -z "$RB_TEMP" ] ; then
    PKGLIST="$PKGLIST $PKG"
    fi
    #v-

    Then, following the fi, the exit status is zero for both the command and
    the function, and all following commands are executed. The following
    also works:

    #v+
    [ ! -z "$RB_TEMP" ] || PKGLIST="$PKGLIST $PKG"
    #v-

    Because the exit status of the first command on the line is zero if
    RB_TEMP is not zero length.

    So, there's a fix for it. Figured I'd post this FTR, just in case
    someone else has a lack of brain bytes similar to mine. ;]

    Regards,
    --
    dave [ please don't CC me ]
    David Guest

Similar Threads

  1. Accordion oddness
    By fancellu in forum Macromedia Flex General Discussion
    Replies: 1
    Last Post: March 6th, 05:40 PM
  2. Lexmark C910 oddness
    By Jeremy_Matthews@adobeforums.com in forum Adobe Acrobat Macintosh
    Replies: 3
    Last Post: August 11th, 01:13 PM
  3. NIM oddness
    By Mike in forum AIX
    Replies: 3
    Last Post: January 20th, 07:33 PM
  4. [PHP-DEV] MZ-S oddness
    By Kevin Waterson in forum PHP Development
    Replies: 1
    Last Post: November 5th, 08:02 AM
  5. Rubygarden oddness
    By Berger, Daniel in forum Ruby
    Replies: 4
    Last Post: October 15th, 07:18 PM

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
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139