Dear All,
Please advice about this issue.
when i run this line in a script
if [ "${x}" = "test3" ] && [ "${y}" != "test3" ] || [ "${x}" = "test2" ] && [ "${y}" != "test2" ] || [ "${x}" = "test1" ] && [ "${y}" != "test1" ]
if i enter $x = test3 and $y = test1 the If condition apply while it should not
Best Regards
methyl
2
I don't think that "&&" and "||" are suitable for nested conditions. Paraphrasing the condition into nested "ands" and "ors" we get.
#!/bin/ksh
x="test3"
y="test1"
if [ \( "${x}" = "test3" -a "${y}" != "test3" \) -o \( "${x}" = "test2" -a "${y}" != "test2" \) -o \( "${x}" = "test1" -a "${y}" != "test1" \) ]
then
echo "true"
else
echo "false"
fi
true
Was this what you meant?
thank you so much
it works gr8