Why `echo -n` doesn't work in this script on mac terminal? I am learning shell from tutorialspoint today:http://www.tutorialspoint.com/unix/unix-shell-loops.htm

And I copied this code block to a loop.sh file:

#!/bin/sh

a=0
while [ "$a" -lt 10 ]    # this is loop1
do
   b="$a"
   while [ "$b" -ge 0 ]  # this is loop2
   do
      echo -n "$b "
      b=`expr $b - 1`
   done
   echo
   a=`expr $a + 1`
done


But when excute it, I got things like:

...
-n 4
-n 3
-n 2
-n 1
-n 0
...


Apparently, the -n flag doesn't work in echo -n "$b ".

Then I move the same file to my Ubuntu virtual system. Runs it.

I got ：

0
1 0
2 1 0
3 2 1 0
4 3 2 1 0
5 4 3 2 1 0
6 5 4 3 2 1 0
7 6 5 4 3 2 1 0
8 7 6 5 4 3 2 1 0
9 8 7 6 5 4 3 2 1 0


I'm confused, though Ubuntu use dash as its default sh, but OSX use official bourne shell as its sh, why the script failed here? How to fix it?
Echo is both a binary program (/bin/echo) as well as builtin command in some shells such as bash and sh.  As man echo states, 


 Some shells may provide a builtin echo command which is similar or iden-
 tical to this utility.  Most notably, the builtin echo in sh(1) does not
 accept the -n option.  Consult the builtin(1) manual page.



In order to fix this, you can change your script to use bash by setting the first line to 

#!/bin/bash


Or change your invocation of echo to

/bin/echo -n "$b "