I have a script that compiles a .bashrc file. It tests if certain commands are available. It generates variables like so:
command -v cheat 2>&1 >/dev/null
HAS_CHEAT=$?
command -v git 2>&1 >/dev/null
HAS_GIT=$?
Other files in the script will take or not take certain actions if these variables are set.
The problem I'm having is that after .bashrc is loaded, my environment is polluted with these variables. I'd like to not have to unset each and every variable manually. Wondering if there is a better way to do it.
env | grep ^HAS_? You can loop over the results and unset them programmatically.envlist all your environment variables for the current session. Take a look also onsetand remember,manis your friend.HAS_CHEATet al. are not environment variables; they are regular shell variables.