Skip to content
Advertisement

Embedding bash commands

I’m using virtualenvwrapper and trying to create a virtualenv using a version of python that’s not the default.

What I’d like to do is:

$ which python2.7
>> /usr/local/bin/python2.7
$ mkvirtualenv -p /usr/local/bin/python2.7 env

…But without the copy-paste. Is there a way to do this in one line?

Advertisement

Answer

mkvirtualenv -p "$(type -P python2.7)" env

is the correct way to write this as a one-liner. type is a POSIX standard utility, so it is more likely to exist and work consistently across POSIX-ish systems than which.

User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement