Exactly. The #!/bin/bash says to run the script using /bin/bash, but by running it with sh ex1.sh, you ignore that and run it using sh. Just run it as ./ex1.sh. (And the .sh suffix isn't really needed.)
0
Your "shebang" lines uses bash shell ("/bin/bash") but you're probably invoking another shell ("sh") invoking another shell to execute your script. Try this :
$ chmod 700 ex1.sh
This will make your script executable. Then run it :
bash ex1.shwhen you want to usebashfeatures (not found in the POSIX shell).