virtualenvwrapper.sh中的"$(command which python 财富值54

2016-10-31 23:16发布

描述问题

意思: 获取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

问题简化

友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
该问题目前已经被作者或者管理员关闭, 无法添加新回复
3条回答

bash 文档中的解释:

作者在这一段注释中已经说明了,目的是为了多平台兼容

没有任何道理,可能这个脚本的作者是个老古董,不习惯bash吧。

一周热门 更多>