well, it all depends on how you execute your script, if your goal is to indeed execute it and expand your environment, you have no much choice than using the (
and )
to fork a shell and have all variables executed within kept in its scope or using unset
at the end of the bash script to remove all unwanted variables from the shell.
Otherwise, you can simply have your script executed "normally" throuh a fork, and then have all the variables are not getting out of the called's scope when giving back control to the calling shell.
In the end, you're not giving enough context to give a definite and precise answer to your question… other than just general advices.