Register
It is currently Thu Oct 30, 2014 10:00 pm

Need a little help with script


All times are UTC - 6 hours


Post new topic Reply to topic  [ 3 posts ] 
Author Message
 PostPosted: Fri Mar 21, 2014 9:49 am   

Joined: Fri Mar 21, 2014 9:34 am
Posts: 2
I am kind of a noob to bash scripting and I was playing with a script to learn. I was trying to write a script that would allow me to input multiple ip addresses into a text file. Unfortunately, the script is not performing as I would expect. Could someone help me learn and tell me what I am doing wrong? I would appreciate any help or suggestions

Here is what I have:


echo "Input IP Address, followed by ENTER:"

read IP
echo "$IP" >> ip.blocked

echo "Do you have more to enter, Y or N?"
read var

while [ $var="Y" ]; do



echo "Input IP Address, followed by ENTER:"

read IP
echo "$IP" >> ip.blocked
echo "Do you have more to enter, Y or N?"
read var
done



When I run it, no matter what input I give, it continues to loop. I would expect that anything but a Y would end the script. But for soome reason, it continues to loop. I am assuming that the variable is not changing, but I do not have enough knowledge to figure out why. Thanks


Top
 Profile  
 PostPosted: Fri Mar 21, 2014 9:58 am   

Joined: Mon Mar 02, 2009 3:03 am
Posts: 550
hi,

Code:
while [ $var="Y" ]
assignment is always true (unless command substitution returns false).
tests need spaces around the equal sign.


Top
 Profile  
 PostPosted: Fri Mar 21, 2014 10:30 am   

Joined: Fri Mar 21, 2014 9:34 am
Posts: 2
Wow, that was the ticket. Thanks.


Top
 Profile  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: No registered users and 6 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
cron


BashScripts | Promote Your Page Too
Powered by phpBB © 2011 phpBB Group
© 2003 - 2011 USA LINUX USERS GROUP