I use dig to find the IP of a subdomain and assign it to a variable called string. This subdomain has 2 IPs and the IPs are separated by space. I want to say that if there is a space in the string, announce it. I use this code:
#!/bin/bash
string=$(dig +short google.com)
echo $string
if [[ "$string" =~ \ |\' ]] # slightly more readable: if [[ "$string" =~>
then
echo "Matches"
else
echo "No matches"
fi
Although there is a space in "string", it says "no matches". I also tried newline character (\n), it wasn't detected as well. What's wrong?