Register
It is currently Fri Oct 24, 2014 9:22 am

Simple read file help


All times are UTC - 6 hours


Post new topic Reply to topic  [ 3 posts ] 
Author Message
 PostPosted: Fri May 28, 2010 2:37 am   

Joined: Fri May 28, 2010 2:34 am
Posts: 1
all i need too do, is read a file, assign the number too variable, and use an if statement soo see if the number is 1 or 0
Code:
my_variable2= cat truec
my_variable= cat config
echo $my_variable
echo $my_variable2

if [ "$my_variable" = "$my_variable2" ]; then
   echo "working"
else
   echo "not"


config contains the number 2 and truec the number 1, yet it always says they are equal and outputs working.

its probably somthing simple

thanks for any help!


Top
 Profile  
 PostPosted: Fri May 28, 2010 2:59 am   
Moderator
User avatar

Joined: Thu Oct 11, 2007 7:12 am
Posts: 229
Location: London - UK
Code:
my_variable2=$(cat truec)
my_variable=$(cat config)

echo $my_variable
echo $my_variable2

if [ "$my_variable" == "$my_variable2" ]; then
   echo "working"
else
   echo "not"
fi


Top
 Profile  
 PostPosted: Sat May 29, 2010 2:30 am   

Joined: Wed Apr 14, 2010 10:23 am
Posts: 17
Also consider to use the following syntax:
Code:
var=$(< file)


Just optics for you, nothing serious.


Top
 Profile WWW  
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 7 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