BashScripts.org
http://bashscripts.org/forum/

Simple read file help
http://bashscripts.org/forum/viewtopic.php?f=15&t=1116
Page 1 of 1

Author:  Willo [ Fri May 28, 2010 2:37 am ]
Post subject:  Simple read file help

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!

Author:  DarthWavy [ Fri May 28, 2010 2:59 am ]
Post subject:  Re: Simple read file help

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

Author:  TheBonsai [ Sat May 29, 2010 2:30 am ]
Post subject:  Re: Simple read file help

Also consider to use the following syntax:
Code:
var=$(< file)


Just optics for you, nothing serious.

Page 1 of 1 All times are UTC - 6 hours
© 2000, 2002, 2005, 2007 phpBB Group • http://www.phpbb.com