From 376e07e464d5d713ba9f359dcfbdcd1fb6fb0d23 Mon Sep 17 00:00:00 2001 From: Daniel Hahler Date: Mon, 2 Mar 2015 21:30:03 +0100 Subject: [PATCH] activate.sh: handle empty (but set) vars Fixes https://github.com/pypa/virtualenv/issues/407 --- virtualenv_embedded/activate.sh | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/virtualenv_embedded/activate.sh b/virtualenv_embedded/activate.sh index e50c78256..a142c51c6 100644 --- a/virtualenv_embedded/activate.sh +++ b/virtualenv_embedded/activate.sh @@ -5,12 +5,12 @@ deactivate () { unset pydoc # reset old environment variables - if [ -n "$_OLD_VIRTUAL_PATH" ] ; then + if ! [ -z "${_OLD_VIRTUAL_PATH+x}" ] ; then PATH="$_OLD_VIRTUAL_PATH" export PATH unset _OLD_VIRTUAL_PATH fi - if [ -n "$_OLD_VIRTUAL_PYTHONHOME" ] ; then + if ! [ -z "${_OLD_VIRTUAL_PYTHONHOME+x}" ] ; then PYTHONHOME="$_OLD_VIRTUAL_PYTHONHOME" export PYTHONHOME unset _OLD_VIRTUAL_PYTHONHOME @@ -23,7 +23,7 @@ deactivate () { hash -r 2>/dev/null fi - if [ -n "$_OLD_VIRTUAL_PS1" ] ; then + if ! [ -z "${_OLD_VIRTUAL_PS1+x}" ] ; then PS1="$_OLD_VIRTUAL_PS1" export PS1 unset _OLD_VIRTUAL_PS1 @@ -46,10 +46,8 @@ _OLD_VIRTUAL_PATH="$PATH" PATH="$VIRTUAL_ENV/__BIN_NAME__:$PATH" export PATH -# unset PYTHONHOME if set -# this will fail if PYTHONHOME is set to the empty string (which is bad anyway) -# could use `if (set -u; : $PYTHONHOME) ;` in bash -if [ -n "$PYTHONHOME" ] ; then +# Unset PYTHONHOME if set. +if ! [ -z ${PYTHONHOME+x} ] ; then _OLD_VIRTUAL_PYTHONHOME="$PYTHONHOME" unset PYTHONHOME fi