我一直在编写一个bash脚本,我无法弄清楚为什么!=运算符无效。
#/bin/bash
vips=()
vips+=(" Ltm::HTTP Profile: Default_HTTP_Profile")
vips+=(" Ltm::Virtual Address: 10.206.16.76")
for i in "${vips[@]}";
do
if [[ $i != *"TCP Profile"* ]] || [[ $i != *"OneConnect"* ]] || [[ $i != *"HTTP Profile"* ]]; then
echo "test"
fi
done
for i in "${vips[@]}";
do
echo "$i"
done
结果是
test
test
Ltm::HTTP Profile: Default_HTTP_Profile
Ltm::Virtual Address: 10.206.16.76
如您所见,第二个数组元素不应与if逻辑匹配。
答案 0 :(得分:1)
让我们跟踪它的执行方式:
i=" Ltm::HTTP Profile: Default_HTTP_Profile"
if [[ $i != *"TCP Profile"* ]] || [[ $i != *"OneConnect"* ]] || [[ $i != *"HTTP Profile"* ]]; then
首先,它运行[[ $i != *"TCP Profile"* ]]
。此测试返回true,因为该字符串不包含TCP Profile
。因此,if
作为一个整体是正确的,并且它不需要运行任何其他测试。
您可能想要的内容如下:
case $i in
*"TCP Profile"*|*"OneConnect"*|*"HTTP Profile"*) : ;; # do nothing
*) echo "test" ;;
esac
......或者:
if ! [[ $i = *"TCP Profile"* || $i = *"OneConnect"* || $i = *"HTTP Profile"* ]]; then
echo "test"
fi
答案 1 :(得分:0)
我修改了我的逻辑如下,它的工作原理。谢谢您的帮助。
With Phone as (SELECT phone_id, patient_id, phone_type, PD.Number, row_number() over (partition by Patient_ID order by PD.Number) as RN
FROM Phone_type PT
INNER JOIN Phone_Details PD
ON PT.Phone_ID = PD.Phone_ID
WHERE Phone_Type = 1),
Fax as (SELECT phone_id, patient_id, phone_type, PD.Number, row_number() over (partition by Patient_ID order by PD.Number) as RN
FROM Phone_type PT
INNER JOIN Phone_Details PD
ON PT.Phone_ID = PD.Phone_ID
WHERE Phone_Type = 1)
SELECT *
FROM PHONE P
FULL OUTER JOIN FAX F
on P.Patent_Id =F.PatentID
and P.RN=F.RN