10
我看的virtualenv的源代码,并激活脚本包含以下代码:if [[x]!= x]在bash中做什么?
if [ -z "$VIRTUAL_ENV_DISABLE_PROMPT" ] ; then
_OLD_VIRTUAL_PS1="$PS1"
if [ "x" != x ] ; then
PS1="$PS1"
else
if [ "`basename \"$VIRTUAL_ENV\"`" = "__" ] ; then
# special case for Aspen magic directories
# see http://www.zetadev.com/software/aspen/
PS1="[`basename \`dirname \"$VIRTUAL_ENV\"\``] $PS1"
else
PS1="(`basename \"$VIRTUAL_ENV\"`)$PS1"
fi
fi
export PS1
fi
是什么行吗? x在脚本的其他地方没有定义。
它看起来像旧的'[“x $ foo”!= x]'用来检查旧壳上的空字符串。 –
这正是发生了什么事。该脚本是自动生成的,有时候会有一个变量在那里被拼接。见[this](https://github.com/pypa/virtualenv/blob/develop/virtualenv_embedded/activate.sh#L59)和[this](https://github.com/pypa/virtualenv/blob/develop/) virtualenv.py#L1582)。谢谢! –
@AKaptur:不客气! – ruakh