1

I've tried Googling a lot I am still not able to find solution

rm -y zoznam
tomatch=1000000000
treshold=10
okvalue=`expr "$tomatch" / 100 * "$treshold"`

while read hostname sum size znak
do
        while [ "$tomatch" -gt "$okvalue" ]
        do
                if [ "$tomatch" -gt "$size" ]
                then
                echo $hostname >> zoznam
                tomatch=`expr "$tomatch" - "$size"`
                fi
        done

done < weeklysize

I get line 8: [: : integer expression expected please help

2
  • 1
    What value does $okvalue have? It seems to me that it is not an integer.
    – fedorqui
    Mar 13, 2014 at 14:07
  • 1
    Add to the top of your shell script set -xv. This will turn on debugging, and will help you see what values are in your if statement. I suspect that $size is not what you think it is.
    – David W.
    Mar 13, 2014 at 14:12

2 Answers 2

2

There's no need to use expr for arithmetic, unless you are using an archaic shell:

okvalue=$(( $tomatch / 100 * $treshold ))

This will avoid your actual problem of needing to escape *, as well as avoiding the need to spawn an external program.

Similarly, you can increment tomatch with

: $(( tomatch += $size ))

( or simply (( $tomatch += $size )) to use a bash arithmetic command ).

0
0

You need to escape the * in okvalues assignment:

okvalue=`expr "$tomatch" / 100 \* "$treshold"`

You could alternatively evaluate the expression using bc

okvalue=$(echo "$tomatch / 100 * $treshold" | bc)

If you are using bash, you could instead do:

okvalue=$(bc <<<"$tomatch / 100 * $treshold")

Or even just:

okvalue=$((tomatch / 100 * treshold))

You don't need the $ inside the (( )) as explained here

For sake of completeness, I will also mention let, which is also mentioned in the above link:

let okvalue="tomatch / 100 * treshold"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.