You should run your script with bash
, i.e. either bash ./script.sh
or making use of the shebang by ./script.sh
after setting it to executable. Only running it with sh ./script.sh
do I get your error, as commented by Cyrus.
See also: role of shebang at unix.SE