0

I wrote a fairly straightforward script to map out what one-word domains are still available. I'm getting an error in line 7, the if clause, but I can't see anything wrong with it.

#!/bin/bash

for i in $(cat /usr/share/dict/words);
do
        i="$i.com"
        echo $i processing `date`
        if [ $(whois $i) == "*No match for*" ]
        then
                echo $i AVAILABLE
#               echo "$i">>domains.available.`date "+%Y%m%d"`
        else
                echo $i unavailable
#               echo "$i">>domains.unavailable.`date "+%Y%m%d"`
        fi
done

I looked up similarly straightforward scripts online, and they seem syntactically identical.

jonrsharpe
  • 115,751
  • 26
  • 228
  • 437
RPNS
  • 3
  • 5

2 Answers2

1

Try double brackets and the * outside the quotes

if [[ $(whois $i) == *"No match for"* ]]
papkass
  • 1,261
  • 2
  • 14
  • 20
1

Quote the argument:

if [ "$(whois $i)" == "*No match for*" ]

Otherwise all the words of the response will be split into separate arguments to the test command.

Or you could use the built-in conditional operator. It doesn't do word splitting of variables or command substitutions.

if [[ $(whois $i) == "*No match for*" ]]
Barmar
  • 741,623
  • 53
  • 500
  • 612
  • The latter (double-brackets for the built-in conditional operator) does in fact resolve the error, but silently gives me false negatives consistently. In other words, `$i=notarealdomainatall.com` still flows to the else block. – RPNS Nov 09 '15 at 22:23
  • Are you expecting `==` to do a pattern match instead of an exact match? Wildcards inside quotes are not considered pattern characters. – Barmar Nov 09 '15 at 22:24
  • Ah, yes I was! '*No match for*' is an unlikely literal string to result from a whois query ;-) – RPNS Nov 09 '15 at 22:27