Question

If you introduce variable in Bash include scripts it will be available in original environment and possible conflict with original environment.

Is it possible to prevent pollution on original environment?

From virtualenv-bin/activate and /etc/bash_completion scripts:

  • I see unset and unique prefixes, like _LIB.

  • Another way to wrap code in function and use non-POSIX local keyword. But function name can possibly conflict with original environment. I don't know how to create andinvoke anonymous function in Bash...

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top