LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 05-06-2004, 09:35 AM   #1
nice
LQ Newbie
 
Registered: Oct 2003
Posts: 3

Rep: Reputation: 0
bash script help


hi all,

i have a problem with this script, the variable MacAdd isn't usable outside the internal while !

Please help me

Thanks

#!/usr/bin/bash
cat source.txt | while read LineS; do
tokenS=`echo $LineS |awk '{ print $1 }'`
MacAdd=""
cat FileDb.txt | while read LineDb; do
tokenDb=`echo $LineDb |awk '{ print $1 }'`
# echo $tokenS " " $tokenDb
if [ "$tokenS" != "$tokenDb" ]
then
MacAdd=$tokenS
# echo "not equal"
else
MacAdd=""
# echo "string equal"
fi
done
if [ "$MacAdd" == "" ]
then
echo "string empty"
else
echo "mac address " $MacAdd
fi
done
 
Old 05-06-2004, 09:45 PM   #2
meonkeys
Member
 
Registered: Apr 2004
Location: Minneapolis
Distribution: Ubuntu
Posts: 45

Rep: Reputation: 15
Could you put the shell script inside [code][/code] tags?
 
Old 05-07-2004, 12:38 AM   #3
bigrigdriver
LQ Addict
 
Registered: Jul 2002
Location: East Centra Illinois, USA
Distribution: Debian stable
Posts: 5,908

Rep: Reputation: 356Reputation: 356Reputation: 356Reputation: 356
Take the first declaration of the variable MacADD out of the first while loop, and place it one line before the cat statement. That should make it global to the entire script. I'm not certain, but declaring it in a loop may limit the scope of the variable.
 
Old 05-07-2004, 04:07 AM   #4
nice
LQ Newbie
 
Registered: Oct 2003
Posts: 3

Original Poster
Rep: Reputation: 0
Talking

hi all

I've resolved the script problem modify it

#!/usr/bin/bash
cat source.txt |
while read LineS; do
tokenS=`echo $LineS |awk '{ print $1 }'`
#echo "sorg "$tokenS
MacAdd=`cat FileDb.txt | grep $tokenS | awk '{ print $1 }'`
#echo "DB "$MacAdd
if [ "$MacAdd" == "" ]
then
echo "MacAddress "$tokenS
fi
done
exit


Thanks
 
  


Reply



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



Similar Threads
Thread Thread Starter Forum Replies Last Post
Bash script Linh Programming 4 04-21-2004 05:19 PM
send automatic input to a script called by another script in bash programming jorgecab Programming 2 04-01-2004 12:20 AM
bash script - incrementing a filename in a script tslinux Programming 10 08-05-2003 11:58 PM
bash script brian0918 Programming 7 06-12-2003 06:06 PM
bash script prob: how can i tell the script that a 'dd' has finished? Frustin Linux - General 2 04-02-2003 05:34 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 01:07 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration