I am a beginner in bash and trying to nest for and if loop. I have written the below script to fetch all the EC2 instances from all the regions of my aws environment. The script syntax checks are fine, but when running the script getting below error. It seems the if condition is throwing error. Would appreciate if someone can point where I am going wrong.
main.sh: 11: [[: not found
main.sh: 23: [[: not found
main.sh: 11: [[: not found
main.sh: 23: [[: not found
Script:
#!/bin/bash
date=$(date +"%B-%Y")
echo Get instances in all regions....
  for env in stage prod 
    do
      if [[ "$env" == stage ]]; then
        #Get all the aws regions
        for region in $(aws ec2 describe-regions --output text | cut -f4)
        do
          #List Resources through aws CLI command and store in CSV file
          aws ec2 describe-instances --region "$region" --query 'Reservations[].Instances[].[Tags[?Key=='"'Name'"']|[0].Value,InstanceId,State.Name,InstanceType,PublicIpAddress,PrivateIpAddress,Placement.AvailabilityZone,Platform]' --output text --profile pepsico-stage | sed -E 's/\s+/,/g' | grep -v "windows" >> ec2stagelist-"$date".csv
        done
      elif [[ "$env" == prod ]]; then
          #Get all the aws regions
        for region in $(aws ec2 describe-regions --output text | cut -f4)
        do
          #List Resources through aws CLI command and store in CSV file
          aws ec2 describe-instances --region "$region" --query 'Reservations[].Instances[].[Tags[?Key=='"'Name'"']|[0].Value,InstanceId,State.Name,InstanceType,PublicIpAddress,PrivateIpAddress,Placement.AvailabilityZone,Platform]' --output text --profile pepsico-prod | sed -E 's/\s+/,/g' | grep -v "windows" >> ec2prodlist-"$date".csv
        done
      fi
    done
 
    