head, tail and wc
If your busybox has head , tail and wc , you can try the following:
head -c $n2 /dev/zero | tail -c +$n1 | wc -c
The first will generate a sequence of n2 null bytes. The second will start at position n1 , counting from 1, so it skips n1 - 1 bytes. Therefore, the resulting sequence has n2 - n1 + 1 bytes. This score can be calculated using wc -c .
head, tail and ls or stat
Tried this with my boot field, although its configuration may be different from yours. I'm not sure if wc will be more likely than expr . If you have head and tail , but no wc , you can write the result to a temporary file, and then use stat or ls to get the size as a string. Examples for this are given below.
seq and wc
If you have wc but not head and tail , you can replace seq instead:
seq $n1 $n2 | wc -l
seq, tr and stat
Your comment states that you do not have wc , but you have seq , here is an alternative if you complete ls as well as tr , enough, possibly even stat . Alas, I just noticed that tr also not on your list of applets. However, for future reference here:
seq $n1 $n2 | tr -d [0-9] > tempfilename stat -c%s tempfilename
This creates a sequence of lines n2 - n1 + 1 , and then deletes all the digits, leaving only the many lines of the new line that it writes to the file. Then we print its size.
dd and ls
But since you do not have tr , you will need something else. dd can suit your needs as you can use it a bit like head or tail .
dd if=/dev/zero of=tmp1 bs=1 count=$n2
This creates a sequence of n2 null bytes, and then skips the first n1 . It adds one new row to add 1 to its size. He then uses ls to print the size of this file and sets the positional variables $1 , $2 , ... based on his output. $6 should be a column containing the size. If I did not miss anything, all of this will be available to you.
Busybox alternative
If all else fails, you can still implement your own algorithm for subtracting numbers, using many differences in the case. But this will require a lot of work, so you might be better off sending a statically linked binary expr or something specifically designed for your use case instead of a script.