我只想在找不到其中一个文件夹的情况下执行echo?然而,找到了AEM_SEGMENTSTORE_LOCATION_AZURE,但我仍然得到“未找到回声”
#!/bin/bash
AEM_SEGMENTSTORE_LOCATION="/opt/day/${AEM_RUNMODE}/crx-quickstart/repository/segmentstore"
AEM_SEGMENTSTORE_LOCATION_AZURE="/opt/day/crx-quickstart/repository/segmentstore"
[[ ! -d ${AEM_SEGMENTSTORE_LOCATION} ]] || [[ ! -d ${AEM_SEGMENTSTORE_LOCATION_AZURE} ]] && echo "not found"发布于 2020-07-15 00:13:50
一般来说,不要将||和&&混为一谈。优先级并不是您所期望的。a || b && c等同于(a || b) && c,但a && b || c与(a && b) || c不同。养成使用适当的if语句的习惯。
if [[ ! -d "$AEM_SEGMENTSTORE_LOCATION" || ! -d "$AEM_SEGMENTSTORE_LOCATION_AZURE" ]]; then
echo "not found"
fi或
if ! [[ -d "$AEM_SEGMENTSTORE_LOCATION" && -d "$AEM_SEGMENTSTORE_LOCATION_AZURE" ]]; then
echo "not found"
fi发布于 2020-07-15 00:15:37
优先级是错误的。不管怎么说,你似乎在寻找。您可以通过将其更改为
if [[ ! -d "$AEM_SEGMENTSTORE_LOCATION" ]] &&
[[ ! -d "$AEM_SEGMENTSTORE_LOCATION_AZURE" ]]
then
echo "$0: not found" >&2
fi还要注意变量的正确引号(参见When to wrap quotes around a shell variable;大括号没有引号,在这里基本上没有用),如果变量是你自己的私有变量,可能要避免使用大写的变量名(系统变量保留大写)。最后,诊断消息可能会显示为标准错误,并包含脚本的名称;它可能还会显示未找到的内容。
https://stackoverflow.com/questions/62899369
复制相似问题