I have a script that sets some environment/global variables. It also has a function "deactivate ()" which undoes this sourcing.
source_script.rc
deactivate () {
env_var=$old_env_var
unset $old_env_var
}
old_env_var=$env_var
export env_var=new_value
I want to call deactivate from a program to undo the sourcing. However, when I try
other_program.sh
source /source/script
deactivate
It simply runs the deactivate function without exporting any of the variables to my environment. My question is, is there a way to source the deactivate function from another program so that it will call deactivate and actually set the necessary env variables?