Ubuntu shell script for starting multiple Postgres servers

Your sudo su postgres command starts a new shell, under the "postgres" userid. This new shell doesn't read from the script file, so it never sees the rest of the file.

A better way (that works) is to remove the sudo su postgres command, and preface the remaining two lines with sudo -u postgres. Read man sudo sudoers.