问题
I have a very simple question that I can't answer. In shell, what would this command do:
test -d $VIRTUAL_ENV || virtualenv $VIRTUAL_ENV
It seems like it tests if the virtualenv directory exists, but I dont understand what if does with that information. Will it always create the virtualenv afterwards, or would it only do it if it doesn't already exist?
回答1:
The || is the OR condition. Hence, this will test if $VIRTUAL_ENV directory exists. If not, it will run virtualenv $VIRTUAL_ENV.
Other examples:
$ test -d /tmp || echo "yes"
$
$ test -d /tmpblabla || echo "this dir does not exist"
this dir does not exist
$ test -d /tmp && echo "/tmp exists" || echo "yes"
/tmp exists
回答2:
It tests if the directory $VIRTUAL_ENV exists and otherwise creates it using virtualenv
来源:https://stackoverflow.com/questions/19768796/what-does-this-shell-test-achieve