What does this shell test achieve

前端 未结 2 779
轮回少年
轮回少年 2021-01-29 02:45

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 se

相关标签:
2条回答
  • 2021-01-29 03:42

    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
    
    0 讨论(0)
  • 2021-01-29 03:46

    It tests if the directory $VIRTUAL_ENV exists and otherwise creates it using virtualenv

    0 讨论(0)
提交回复
热议问题