I am trying to unset all environment variables from within a script. The script runs fine but if I run env it still shows all the variables set.
If I run the command from CLI, it works and the variables are unset.
unset `env | awk -F= '/^\w/ {print $1}' | xargs`
Have any idea how to run this from a script?
Also, have any idea how to source /etc/profile from a script? This doesn't work either.
I need to set variables with same names but different paths, depending on the instances my users need.
Later edit:
ok, I ended up with this (rather not elegant, but whatever) solution:
. script
which contains:
unset `env | awk -F= '/^\w/ {print $1}'|egrep -v "HOSTNAME|TERM|SHELL|HISTSIZE|SSH_CLIENT|SSH_TTY|USER|LS_COLORS|KDEDIR|MAIL|PATH|INPUTRC|PWD|LANG|HISTIGNORE|SSH_ASKPASS|TEST|SHLVL|HOME|LD_ASSUME_KERNEL|LOGNAME|SSH_CONNECTION|LESSOPEN|HISTTIMEFORMAT|G_BROKEN_FILENAMES|_"|xargs`
source env_variable_file
Thanks!