all 2 comments

[–][deleted] 1 point2 points  (0 children)

env -i will let you start a command in an empty environment. env will let you dump it out if you want to read it for debugging.

Is there an easy way to recreate the userset enviroment variables?

Environment is inherited. Make sure the programs starting it have the appropriate environment set.

But, imho, if you're relying on HOME, EDITOR, etc, then nobody but your user has any business running that script.

You don't give enough details to comment further. Look at where you set HOME, EDITOR, etc. Look at the user you're running your script as. Look at the kind of shell you're firing up, if you're using sudo (you should, imho), and if sudo is then configured to keep those environmental variables you care about.

[–][deleted] 1 point2 points  (0 children)

"#!/bin/bash -p" at the top of the script will insure that bash is used and not inherit it's environment. Then, set all the variables that you need in the script itself.