def expand_var(s, var, expansions):
    """Expands a template string of the form ${VAR} with each entry of the
    expansions array, then join them in using the same scheme as the PATH
    variable. For example, given:
    s = ${ABC}/stuff
    var = ABC
    expansions = ['a', 'b', 'c'],
    then expand_sub would return 'a/stuff:b/stuff:c/stuff'."""
    results = []
    for expansion in expansions:
        result = s.replace('${%s}' % var, expansion)
        if result not in results:
            results.append(result)
    return ':'.join(results)
