2013-11-04 97 views
0

我有一個非常簡單的問題,我無法回答。在外殼,你會下面命令:這個shell測試實現了什麼

test -d $VIRTUAL_ENV || virtualenv $VIRTUAL_ENV 

好像它測試,如果的virtualenv目錄存在,但我不明白利用這些信息做什麼如果。之後會不會創建virtualenv,還是隻有在它不存在的情況下才會這樣做?

回答

3

||是OR條件。因此,這將測試$VIRTUAL_ENV目錄是否存在。如果不是,它將運行virtualenv $VIRTUAL_ENV

其他例子:

$ 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 
1

它測試,如果該目錄$VIRTUAL_ENV存在,否則創建它使用virtualenv