这个shell测试实现了什么 [英] What does this shell test achieve

查看:27
本文介绍了这个shell测试实现了什么的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个非常简单的问题,我无法回答.在 shell 中,这个命令会做什么:

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

它似乎测试 virtualenv 目录是否存在,但我不明白 if 对这些信息有什么作用.之后它会一直创建virtualenv,还是只在它不存在的情况下才创建?

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?

推荐答案

|| 是 OR 条件.因此,这将测试 $VIRTUAL_ENV 目录是否存在.如果没有,它将运行 virtualenv $VIRTUAL_ENV.

The || is the OR condition. Hence, this will test if $VIRTUAL_ENV directory exists. If not, it will run 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

这篇关于这个shell测试实现了什么的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆