首页 > virtualenvwrapper.sh中的"$(command \which python)"是什么意思?

virtualenvwrapper.sh中的"$(command \which python)"是什么意思?

描述问题

意思: 获取Python的位置
获取Python路径,应该有几种写法,自己一下想到的是which,怎么也不会想到command这种命令(事实上,很少见到这个命令),然考虑到写这个脚本(virtualenvwrapper.sh)的是大神,必然shell编程经验比我丰富,踩过的坑比我多,这样写必然有其道理, 所以这道理是啥?

具体地,我将问题拆解成以下几个:

  1. \which是啥?

  2. $(which python)不可以吗?

  3. command是一个啥命令? (man command没有输出)

上下文环境

Linux
Python2.7

重现

virtualenvwrapper是常用的Python包,它是利用了shell包装了virtualenv,所以我想看看它的shell实现
然发现,有些部分不是很懂

要重现,可以去看virtualenvwrapper.sh这个脚本
注意: 在不同Linux发行版,不同shell(bash/zsh)程序中的位置不同(具体见官方手册)

相关代码

摘取部分代码


# Locate the global Python where virtualenvwrapper is installed.
if [ "$VIRTUALENVWRAPPER_PYTHON" = "" ]
then
    VIRTUALENVWRAPPER_PYTHON="$(command \which python)"
fi

# Set the name of the virtualenv app to use.
if [ "$VIRTUALENVWRAPPER_VIRTUALENV" = "" ]
then
    VIRTUALENVWRAPPER_VIRTUALENV="virtualenv"
fi

# Set the name of the virtualenv-clone app to use.
if [ "$VIRTUALENVWRAPPER_VIRTUALENV_CLONE" = "" ]
then
    VIRTUALENVWRAPPER_VIRTUALENV_CLONE="virtualenv-clone"
fi

已经尝试哪些方法仍然没有解决(附上相关链接)

Google了:

  1. command \which python

问题简化

【热门文章】
【热门文章】