测试两个变量是否同时为空 [英] Test if two variable are empty at the same time

查看:133
本文介绍了测试两个变量是否同时为空的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在相同的if条件下测试两个变量。

I would like to test both variable in the same if condition.

当前,我正在使用[[$ var]]测试一个,但对于两个变量却无法正常工作。

Currently I am using [[ $var ]] to test one but the same for two variable do not work.

为此,我尝试了以下操作:

In order to do that I tried :

if [[ &var1 && &var2 ]]; then
or 
if [[ &ipAddress ]] && [[ &bcastAddress ]]; then

有限制吗?

推荐答案

您可以使用以下组合测试:

You can use this combined test:

[[ -z "${var1}${var2}" ]]

或在相同的如果条件下进行单独的测试:

OR separate tests in same if condition:

[[ -z "$var1" && -z "$var2" ]]

这篇关于测试两个变量是否同时为空的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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