测试两个变量是否同时为空

ogs*_*ogs 3 variables bash conditional-operator

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

目前我使用[[$ var]]来测试一个,但两个变量的相同功能不起作用.

为了做到这一点,我试过:

if [[ &var1 && &var2 ]]; then
or 
if [[ &ipAddress ]] && [[ &bcastAddress ]]; then
Run Code Online (Sandbox Code Playgroud)

有限制吗?

anu*_*ava 5

您可以使用此组合测试:

[[ -z "${var1}${var2}" ]]
Run Code Online (Sandbox Code Playgroud)

或在相同if条件下进行单独测试:

[[ -z "$var1" && -z "$var2" ]]
Run Code Online (Sandbox Code Playgroud)