Bash – Test if a string has a period in it with bash

bashstring

I want to run a bash command on output from Drupal's drush command-line interface. drush site-alias returns a list of webroots, first showing the name of the group, and then each site in that group. The site itself is aliased in the form group.site. For instance, you might get

internal
internal.site1
internal.site2
external
external.site1
external.site2
marketing
marketing.site1
marketing.site2

I want to do a command on each of the site aliases, but not on the group alias itself. I need to test if the string has a period in it, and if so, run it:

for i in $(drush site-alias); do {if no period) drush $i command; done;

How can I run this test?

Best Answer

You can use pattern matching:

for i in $(drush site-alias) ; do
    if [[ $i == *.* ]] ; then
        drush "$i" command
    fi
done