Computernerd
Computernerd

Reputation: 7782

simple shell script syntax error : [ : missing ']'

I am trying to do following shell equivalent of the following c++ script

int x=1;
int y=2;
int k=0;

for (int i=0;i<10;i++)
{
   for (int j=0;j<10;j++)
   {

       if ( (x==1) && (y==2) )
       {
           k=1;
       }

   }
 }

I am always getting weird synatax error like there must be spaces between [ or something else , i am confident its one of these reason

This is what my sample code looks like

    for x in ${title[@]} 
    do

    for y in ${author[@]} 
    do
        if [ [ $x == $1] && [ $y == $2] ]; # error : [: missing ']'
        then
            error=1
            return "$error"
        fi
    done
   done

How do i resolve it

Upvotes: 0

Views: 107

Answers (1)

A. Lefebvre
A. Lefebvre

Reputation: 139

Replace if [ [ $x == $1] && [ $y == $2] ]; by if [[ $x == $1 && $y == $2 ]];

Upvotes: 1

Related Questions