Executing SU in a bash script

Solution 1:

sudo starts a shell unless you instruct it otherwise.

It looks like you actually want to run this script as another user. To do that, try something like this:

#!/bin/bash
if [ `id -nu` != diy ]; then
    sudo -u diy $0 # Re-run this script as user diy
else
    # Everything you want to do goes here
fi

Keep in mind that /etc/sudoers must be set up to allow the original user to run this script as the new user.