Integer expression expected

Newb here

echo "$yesterdaysclose"
echo "$close"
if [ "$(echo "if (${yesterdaysclose} < ${close}) 1" | bc)" -eq 1 ] ; then
echo "stocks moving up"
elif [ "$(echo "if (${yesterdaysclose} > ${close}) 1" | bc)" -eq 1 ] ; then
echo "stock is moving down"
else
echo "no change"
fi

seems to evaluate the floating decimal correctly however returns

./shellscript1.sh: line 17: [: : integer expression expected
./shellscript1.sh: line 19: [: : integer expression expected

ideas?

what is the yesterdaysclose and close? are they equal ?

yesterdayclose and close could be equal but usually are not

9.97
9.97
./shellscript1.sh: line 17: [: : integer expression expected
./shellscript1.sh: line 19: [: : integer expression expected
no change

11.69
11.29
./shellscript1.sh: line 17: [: : integer expression expected
stock is moving down

if --> yesterdaysclose bigger(>) or equal(=) to close val..

$(echo "if (${yesterdaysclose} < ${close}) 1" | bc) --> equals to NULL (because conditon is false ) 

and [ test command does not compare with NULL and integer
you maybe use [[ .. ]] double square brackets for escape any error..

1 Like