[: missing `]'

Hi,

I am getting this error while running the following code.

i=`awk '{print $2}' test1.txt`
j=`awk '{print $4}' test1.txt`
k=`awk '{print $6}' test1.txt`
if [ $i =="Yes" && $j =="Yes" && $k =0 ]; then
echo "Up."
else 
echo "down"
fi
rm -f test.txt test1.txt

error is this:

line 12: [: missing `]'

Please suggest.

What shell are you using? Do your test files have only one line? Is there a typo as test.txt is removed but not mentioned anywhere else? What is the field separator in the test files?

---------- Post updated at 11:08 AM ---------- Previous update was at 10:59 AM ----------

That said, try this:

if [ $"i" == "Yes" ] && [ $"j" == "Yes" ] && [ $"k" == 0 ]; then

If test1.txt has only one line, save the overhead of calling awk 3 times with this:

read field1 i field3 j field5 k therest < test1.txt

You need some whitespace between the operators and the right operands. Also, you may need to quote the variables, depending on their possible contents.

Regards,
Alister