Q:

Use curl to get http code from webpage, using list file

Im am struggeling with a script, and are newbie to shell scripting.  
I am trying to create a script, that will run curl on several websites, from a source file.  
    arr_values=()
#Getting list of domains/websites to check, into array.  
read -ra arr_values <<< $(head -n 999 web.csv)

for s in "${arr_values[@]}"; do
#Running curl on each websites from list. 
  res=$(curl -s -o /dev/null -w "%{http_code}" $s)

if [ $res == "200" ]; then 
    echo "OK"; 
elif
    [ $res == "302" ]; then
    echo "OK";
else
    echo "Error";
fi
done

But i get code 000 when i run without the if statement.  
if i run it manually, it all works fine.  
And results in a 200 or 302.  

A:

Assuming the CSV file is this:
www.yahoo.com
www.google.ca

I.e. one site per line.   Also run dos2unix on the file, to ensure it does not have "\r\n" characters at the end of each line. 
Then, run this code:
#! /bin/bash

arr_values=()
#Getting list of domains/websites to check, into array. 
read -ra arr_values <<< $(head -n 999 web.csv)

for s in "${arr_values[@]}"
do
    #Running curl on each websites from list. 
    res=$(curl -s -o /dev/null -w "%{http_code}" $s)

    if [ $res == "200" ]
    then
        echo "OK $s $res";
    elif [ $res == "302" ]
    then
        echo "OK $s $res";
    else
        echo "Error $s $res";
    fi
done

And got this output:
./t.bash 
Error www.yahoo.com 301
OK www.google.ca 200

What was modified:

if conditions are verified using '=='
Modified the echo statements a bit to make it easier to debug

