0

I'm trying to search for multiple domain names availability with this script but it doesn't work, where's the mistake? thanks

#!/bin/bash 

WEB=('madmane1' 'madmane2' 'madmane3' 'madmane4' 'madmane5' 'madmane6' 'madmane7' 'madmane8' 'madmane9')
 
ELEMENTS=${#WEB[@]} 
 
for (( i=0;i<$ELEMENTS;i++)); do 
      whois ${WEB[${i}]}$'.com' | egrep -q \ 
      '^No match|^NOT FOUND|^Not fo|AVAILABLE|^No Data Fou|has not been regi|No entri' 
      if [ $? -eq 0 ]; then 
          echo "${WEB[${i}]}$'.com' : available" 
      fi 
done 

here's the error:

line 9: ^No match|^NOT FOUND|^Not fo|AVAILABLE|^No Data Fou|has not been regi|No entri: command not found
Mhmd Admn
  • 357
  • 3
  • 10

2 Answers2

1

Assigning stuff to an array and then wrecking it by assigning it to a string without quoting seems like the main mistake here, though it's not the reason you are getting a syntax error.

You also want to avoid testing ”$?” to see if a command succeeded or not, an anti-pattern

See also Correct Bash and shell script variable capitalization

The reason for the error message seems to be a space after the backslash, so you are escaping the space instead of the newline, and thus the shell (in some sense correctly) parses the next line as a new command.

#!/bin/bash 

web=('madmane1' 'madmane2' 'madmane3' 'madmane4' 'madmane5' 'madmane6' 'madmane7' 'madmane8' 'madmane9')
 
for domain in "${web[@]}"; do
    if whois "$domain.com" |
        grep -Eq '^No match|^NOT FOUND|^Not fo|AVAILABLE|^No Data Fou|has not been regi|No entri' 
    then 
        echo "$domain.com: available" 
    fi 
done

Going forward, probably try http://shellcheck.net/ before asking for human assistance.

tripleee
  • 175,061
  • 34
  • 275
  • 318
0

I think I fixed the problem with https://www.shellcheck.net/ here it is now:

#!/bin/bash 

WEB=('madmane1' 'madmane2' 'madmane3' 'madmane4' 'madmane5' 'madmane6' 'madmane7' 'madmane8' 'madmane9')
 
ELEMENTS=${#WEB[@]} 
 
for (( i=0;i<$ELEMENTS;i++)); do 
      whois "${WEB[${i}]}"$'.com' | grep -E \
      '^No match|^NOT FOUND|^Not fo|AVAILABLE|^No Data Fou|has not been regi|No entri' 
      if [ $? -eq 0 ]; then 
          echo "${WEB[${i}]}$'.com' : available" 
      fi 
done 
Mhmd Admn
  • 357
  • 3
  • 10