Hello all! I need help in debugging following script. I have no idea where I am going wrong.
#!/bin/bash
for p1 in A1 TM MP
do
for p2 in A1 TM MP
do
for mp1 in N1 N2
do
for mp2 in N1 N2
do
for mp3 in N1 N2
do
for mp4 in N1 N2
do
for mp5 in N1 N2
do
for mp6 in N1 N2
do
for mp7 in N1 N2
do
for mp8 in N1 N2
do
if [ "$mp1" == "N1" || "$mp2" == "N1" || "$mp3" == "N1" || "$mp4" == "N1" || "$mp5" == "N1" || "$mp6" == "N1" || "$mp7" == "N1" || "$mp8" == "N1" ]; then
if [ "$mp1" == "N2" || "$mp2" == "N2" || "$mp3" == "N2" || "$mp4" == "N2" || "$mp5" == "N2" || "$mp6" == "N2" || "$mp7" == "N2" || "$mp8" == "N2" ]; then
echo " $p1 $p2 $mp1 $mp2 $mp3 $mp4 $mp5 $mp6 $mp7 $mp8 "
fi
fi
done
done
done
done
done
done
done
done
done
done
What I want to achieve is, "if" condition must be true only when at least one variable from $mp1 to $mp8 is N1 and at least one variable from $mp1 to $mp8 is N2.
The errors I am getting are:
./script.sh: line 25: N1: command not found
./script.sh: line 25: N2: command not found
./script.sh: line 25: [: missing `]'
Line 25 is the line of first "if" statement
Could you please tell me where I am going wrong. Sorry if the question is noobish. Thanks in advance!
It works now. Here is the script. But when I copy this into different file and execute it, it again gives the same error.
#!/bin/bash
flag=0
for p1 in A1 TM MP
do
for p2 in A1 TM MP
do
if [ "$p1" = "A1" ] && [ "$p2" = "A1" ]; then
flag=1
elif [ "$p1" = "TM" ] && [ "$p2" = "TM" ]; then
flag=1;
elif [ "$p1" = "TM" ] && [ "$p2" = "A1" ]; then
flag=1;
elif [ "$p1" = "MP" ] && [ "$p2" = "MP" ]; then
flag=1;
elif [ "$p1" = "MP" ] && [ "$p2" = "A1" ]; then
flag=1;
elif [ "$p1" = "MP" ] && [ "$p2" = "TM" ]; then
flag=1;
fi
if [ "$flag" -eq "1" ]; then
flag=0
for mp1 in N1 N2
do
for mp2 in N1 N2
do
for mp3 in N1 N2
do
for mp4 in N1 N2
do
for mp5 in N1 N2
do
for mp6 in N1 N2
do
for mp7 in N1 N2
do
for mp8 in N1 N2
do
if [ "$mp1" = "N1" ] || [ "$mp2" = "N1" ] || [ "$mp3" = "N1" ] || [ "$mp4" = "N1" ] || [ "$mp5" = "N1" ] || [ "$mp6" = "N1" ] || [ "$mp7" = "N1" ] || [ "$mp8" = "N1" ]; then
if [ "$mp1" = "N2" ] || [ "$mp2" = "N2" ] || [ "$mp3" = "N2" ] || [ "$mp4" = "N2" ] || [ "$mp5" = "N2" ] || [ "$mp6" = "N2" ] || [ "$mp7" = "N2" ] || [ "$mp8" = "N2" ]; then
echo " $p1 $p2 $mp1 $mp2 $mp3 $mp4 $mp5 $mp6 $mp7 $mp8 " >> Results.log
fi
fi
done
done
done
done
done
done
done
done
fi
done
done
echo Done.
BTW, I'm modifying the script on Windows machine and copying it over to Linux machine (must do like this for some reason). I also tried "dos2unix script.sh" but no use.'
Has it got something to do with ASCII and UTF-8 formatting and stuff