Bash pattern matching inside [[ test block
<p>I am making a script that can do the same task on several machines, like this:</p>

<pre><code>#!/bin/bash
if [[ hostname = login.machine1 ]]; then
    #do things how they are done on machine1
    ...
elif [[ hostname = login.machine2 ]]; then
    #etc.
fi
</code></pre>

<p>Problem: some machines have several login nodes, like <code>login1.machine2</code>, <code>login2.machine2</code>, etc.  I have tried shell pattern matching and regex but none of them work:</p>

<pre><code>if [[ hostname = login?.machine2 ]]
if [[ hostname == login?.machine2 ]]
if [[ hostname =~ login[0-9].machine2 ]]
if [[ hostname =~ login[0-9]\.machine2 ]]
</code></pre>

<p>and at least a dozen similar patterns, with or without quotes, etc.  What is the correct way to make a test that will return true if hostname = login1.machine2 OR login2.machine2, etc.?  Bonus points for something that works with <code>[</code> instead of <code>[[</code>.</p>