0

Can someone tell me why I am getting this error Message ?

#!/bin/bash
while read LINE; do
        curl -o /dev/null --silent --head --write-out '%{http_code}' "$LINE"
        if [ $http_code != 200]; then
                echo " $LINE URL not available"
                exit 1
        fi
        echo " $LINE"
        done < url-list.txt
Gilles Quénot
  • 173,512
  • 41
  • 224
  • 223
Nabeel A.Rahman
  • 181
  • 3
  • 14

1 Answers1

0

You try to use $http_code, but never declare it, and moreover, space is mandatory before closing test ]

So :

#!/bin/bash
while read url; do
    http_code=$(curl -o /dev/null --silent --head --write-out '%{http_code}' "$url")
    if ((http_code != 200)); then
        echo " $url URL not available"
        exit 1
    fi
    echo " $url"
done < url-list.txt

Note :

  • (( )) is for bash arithmetic
  • prefer the bash test in the form [[ ]], it's more powerfull and less error prone
Gilles Quénot
  • 173,512
  • 41
  • 224
  • 223