<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def substitute(script, submap):
 """Check for presence of template indicator and if found, perform variable substition on script based on template type, returning script."""


    match = config.TEMPLATE_RE.search(script)
    if match:
        template_type = match.groupdict()['type']
        try:
            return config.TEMPLATE_TYPEMAP[template_type](script, submap)
        except KeyError:
            logger.error('Unsupported template type: %s' % template_type)
            raise
    return script