Results 1 to 2 of 2
  1. #1
    Join Date
    Aug 2003
    Posts
    1

    Angry Unanswered: bash logic error

    it appears i have a logic error in this script, i cant find it and am prepaired to blame bash (i wrote this in about 10 minutes in perl TWICE and it worked) after 5 hours on this i will never again write another bash script. why is this broken?

    #!/bin/bash

    FILENAME=dhcp.leases

    if [[ "$1" == "" ]]
    then
    echo "Search term?"
    else
    start="lease $1 {"

    cat $FILENAME | while read i
    do
    if [[ "$i" == "$start" ]]
    then
    echo $i
    junk="works"
    elif [[ "$junk" != "" ]]
    then
    echo $i
    fi
    if [[ $i == "}" ]]
    then
    junk=unset
    fi
    done
    fi

    thats it, the entire file

    here is a dhcp.leases file
    lease 10.2.56.35 {
    starts 3 2003/08/20 12:24:45;
    ends 4 2003/08/21 00:24:45;
    hardware ethernet 00:e0:98:47:28:6c;
    uid 01:00:e0:98:47:28:6c;
    client-hostname "name";
    }
    lease 10.2.56.40 {
    starts 3 2003/08/20 10:37:28;
    ends 3 2003/08/20 22:37:28;
    hardware ethernet 00:20:af:52:02:cf;
    uid 01:00:20:af:52:02:cf;
    client-hostname "thing";
    }
    lease 10.2.56.35 {
    starts 3 2002/08/20 12:24:45;
    ends 4 2002/08/21 00:24:45;
    hardware ethernet 00:e0:28:87:b2:6c;
    uid 01:00:e0:28:87:b2:6c;
    client-hostname "name";
    }




    if one comments out the elif then the first line is returned (as asked for but nothing else as specified by the loop) but if the elif is not commented out then the entire file (well starting at the first entry in the list) is returned
    Last edited by jcpunk; 08-20-03 at 16:59.

  2. #2
    Join Date
    Jun 2003
    Location
    West Palm Beach, FL
    Posts
    2,713

    Cool

    Change this:

    junk=unset

    with this:

    unset junk

    The person who says it can't be done should not interrupt the person doing it. -- Chinese proverb

Posting Permissions

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