0

I have an if statement that starts with a breaking a domain name into an array using the . as an IFS. If the array has 3 items it does one thing, if it has 2 it does another. I'm interested in the first with three items.

For www.domain.com I would get ['www', 'domain', 'com'].

I need to figure out a way to make www or array[0] one var and combine domain and com or array[1] and array[2] into another var. I've tried but I'm new to this and can't figure it out nor can I find how it do it online.

My if statement code works great:

input=$1

IFS='.' read -r -a domain_dot <<< "$input"

if [ ${#domain_dot[@]} == 3 ]; then
    echo "One"
else
    echo "Two"
fi
2
  • Do IFS='.' read -r var1 var2 var3 <<< "$input"
    – Inian
    Commented May 31, 2019 at 6:31
  • This doesn't help solve if what's entered has a subdomain or not though. If I type domain.com one of these var's doesn't get filled. Also I'm not splitting a string into more var's, I'm splitting an array. Seems different? Commented May 31, 2019 at 14:22

0

Browse other questions tagged or ask your own question.