If this is your first visit, be sure to check out the FAQ by clicking the link above.
You may have to register before you can post: click the register link above to proceed.
To start viewing messages, select the forum that you want to visit from the selection below.
In your command line example, you are using the "bash" shell. However, in your script you are forcing the script to use "sh" shell by including #!/bin/sh.
Change it to #!/bin/bash (or wherever bash shell is installed on your system) and you should see identical results.