Arithmetics in if else statement

hello,

i'm trying to get some deeper view into the shell. at the moment I have following problem with the bash:

I read some numbers via some awk scripts

A=`awk '/id="identifier/ {......}`

which works fine,
then I want to make an if statement whth some calculations. but then it does not work.

READS1=`echo 45`;
READS2=`echo 100`;
if [ $READS1 -gt 2 * $READS2 ]; then echo  "gleich";  else echo "ungleich"; fi;

doesnt work

READS1=`echo 45`;
READS2=`echo 100`;
if [ $READS1 -gt $READS2 ]; then echo  "gleich";  else echo "ungleich"; fi;

does work
I tries some variants, with (),'',`` but no success.

thanks for help

Math doesn't work that way in the shell.

If you have BASH or KSH, you can do math inside $(( )) brackets like

if [ $READS1 -gt $((2 * READS2)) ]; then echo  "gleich";  else echo "ungleich"; fi;

First, let's learn how to set a variable to a value. We don't need echo and all that punctutation. Also,there is never a reason to end a line in Shell with a semi-colon. For readability while testing let's indent our code and build in some diagnostic echo statements:

READS1=45
READS2=100
READS3=$((2 * ${READS2}))
echo "READS1=${READS1}"
echo "READS2=${READS2}"
echo "READS3=${READS3}"
if [ ${READS1} -gt ${READS3} ]
then
     echo  "gleich"
else
     echo "ungleich"
fi

./scriptname
READS1=45
READS2=100
READS3=200
ungleich

Hmm. Doesn't German ungleich mean English unequal ?

ok thank you, the firsthint helped me.
I know that it was not neccessary to make the a=`echo 45` statement. bus I thought there might be some type-difference? are there any types in the bash? a la integer vs. string??

thanks a lot

---------- Post updated at 06:07 PM ---------- Previous update was at 06:02 PM ----------

and yes: ungleich = unequal,
it was a -eq before

Most of the time the Shell will deduce the type according to context. There is a small efficiency benefit from using the Shell typeset command which will be described in the manual for your Shell.