Problem in algebraic substraction

my code is like this

count=`cat /filecount.txt | tail -1 |head -1| awk '{print $1}'`  ###file is having value 264  ####

echo "actual count = $count"

exact_count=`expr $value \* 24`

echo "exact_count= $exact_count"

diff=`expr "$exact_count" - "$count"`

a= exact_count - count

echo " value is &a"
echo "$diff"

but it is showing following error

actual count = 264
exact_count= 264
expr: An integer value was expected.

temp[55]: exact_count:  not found.
 value is &a

temp[55]: exact_count:  not found.
 value is &a

Unless I'm being daft, you don't appear to have specified what $value is, so the command is trying to "Multiply by 24" rather than "$value multiplied by 24"

Robin
Liverpool/Blackburn
UK

dear rbatte1

i am very new to UNIX i am giving full code.the filecount.txt is attached

echo -n "ENTER VALUE BETWEEN 01-31 "
read value
count=`cat /filecount.txt | tail -1 |head -1| awk '{print $1}'`  ###file is having value 264  ####
echo "actual count = $count"
exact_count=`expr $value \* 24`
echo "exact_count= $exact_count"
diff=`expr "$exact_count" - "$count"`
a= exact_count - count
echo " value is &a"
echo "$diff"

error massage is

actual count = 264
exact_count= 264
expr: An integer value was expected.

temp[55]: exact_count:  not found.
 value is &a

temp[55]: exact_count:  not found.
 value is &a

One error is due to value with leading space entered by user. Also I made few correction in your script.

echo -n "ENTER VALUE BETWEEN 01-31 "
read value
count=`tail -1 filecount.txt | tr -d " "`  ###file is having value 264  ####
echo "actual count = $count"
exact_count=`expr $value \* 24`
echo "exact_count= $exact_count"
diff=`expr "$exact_count" - "$count"`
a=`expr "$exact_count" - "$count"`
echo " value is $a"
echo "$diff"
1 Like

thanks 47shailesh

it works perfect.....

Hi sagar,

Did you understand the actual problem with your original script that is pointed out by rbatte1?

OK

count=`cat /filecount.txt | tail -1 |head -1| awk '{print $1}'`  ###file is having value 264  ####

echo "actual count = $count"

exact_count=`expr $count \* 24`

echo "exact_count= $exact_count"

diff=`expr "$exact_count" - "$count"`

a=`expr $exact_count - $count`

echo " value is a  $a"
echo "$diff"

hi ananthap

truly speaking not much.