If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > Unix Shell Scripts > bash logic error

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 08-20-03, 15:46
jcpunk jcpunk is offline
Registered User
 
Join Date: Aug 2003
Posts: 1
Angry 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 15:59.
Reply With Quote
  #2 (permalink)  
Old 08-20-03, 18:15
LKBrwn_DBA LKBrwn_DBA is offline
Registered User
 
Join Date: Jun 2003
Location: West Palm Beach, FL
Posts: 2,456
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
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On