-1

Here's what I've attempted:

$var=$(wget --spider -S "http://www.test.com/images/$image" 2>&1 | grep "HTTP/" | awk '{print $2}')
    if [ $var -eq 200 ]; then
        echo "$image|found" >> foundimages.txt
    fi

I need the result dropped into var and I need to compare it. This attempt fails to store that command result. Any ideas?

Jahid
  • 21,542
  • 10
  • 90
  • 108
Geek Grid
  • 207
  • 6
  • 17
  • 1
    `$var=$(command)` is incorrect you want `var=$(command)`. – Etan Reisner May 18 '15 at 15:54
  • 1
    ...mind you, you _also_ should use `[ "$var" = 200 ]`, not `[ $var -eq 200 ]` (Quotes are mandatory for consistent behavior, and string comparison is more appropriate than numeric comparison here, since a value other than a string should return a false result, but not print an error to stderr). Several of these problems would have been caught by http://shellcheck.net/. – Charles Duffy May 18 '15 at 16:30

1 Answers1

2

for assignment var=something not $var=something:

var=$(wget --spider -S "http://www.test.com/images/$image" 2>&1 | grep "HTTP/" | awk '{print $2}')
Jahid
  • 21,542
  • 10
  • 90
  • 108