When the script is executed, it gives the pwd as /opt and the ls lists the contents of /opt. But when I execute pwd from shell, it gives the directory from where I executed the script.
remove the intial #!/bin/sh and try running the script as
#> . script-name
to run the commands in the current shell instead of a subshell. Basically the source command as mentioned by Supreet.
regards, C