hi all.
I'm new to bash programming.
I have a problem with compare bash variable and string from text.
for example.
# I wanted to get maximum page (in this case 16)
cat "page.html" | while read line
do
# I want to read line with pattern something like this <page>Page 1 of 16</page>
if [[ $line == *"Page "*" of "* ]]
then
# I don't really know how sed or awk works, but I found this command produce what I wanted (16).
echo $line | sed -e's/<[^>]*>//g' | awk '{print $4}' > "pageCount"
break
fi
done
#and then I want to compare content of file with my own variable.
#I'm using this command.
c=$(cat "pageCount")
temp=16
if [[ $c == $temp ]]
then
echo "same"
else
echo "different"
fi
I expect the end result will be "same", but actually the result is "different".
how come?
When I echo these two variable, they show same value.
echo "$c $temp" #will produce 16 16
I'm really confused now and really need help.
thanks for helping, and sorry for my bad english.