I created a function that asks a user to guess how many files are in the directory, and I am trying to check whether the input is valid. For line 18, I am trying to check whether the input contains words and if so inform the user that it is not a valid input. However, I receive the following error:
guessinggame.sh: line 18: conditional binary operator expected
guessinggame.sh: line 18: syntax error near `$response'
guessinggame.sh: line 18: `    elif [[ echo $response | egrep "\w" response.txt ]'
Here is my code:
function guessinggame {
num_input=true
while $num_input
do
  echo 'Guess how many files are in the current directory. Type in a number and 
        then press Enter:'
  read response
  echo $response > response.txt
  if [[ $response -eq 3 ]]
  then
    echo 'Congratulations! You guessed correctly!'
    num_input=false
  elif [[ $response -gt 3 ]]
  then
    echo '$response is too high! Guess again.'
  elif [[ $response -lt 3 ]]
  then
    echo '$response is too low! Guess again.'
  elif [[ echo $response | egrep "\w" response.txt ]]
  then
    echo '$response is not a number! Please enter a valid input.'
  else
    echo '$response is not a number! Please enter a valid input.'
  fi
num_input=$num_input
done
}
guessinggame
How do I resolve this error? What am I doing wrong?
 
     
    