I am creating an instance configuration script that sets up a machine.
I am running the script via sudo i.e.
sudo run.sh. Most of the steps require root access but some of the script's steps do no require root access and I prefer running them as the unprivileged user who ran the sudo.
Inside the script running with sudo, I am trying to do
sudo -i -u username sh -c 'echo $MY_ENV'
export MY_ENV=something I expect the above command to print "something"
How can I temporarily switch inside the script to the other user to run commands that include the user's shell env ?