def expandvars(text, environ=None):
if '<STR_LIT:$>' not in text:<EOL><INDENT>return text<EOL><DEDENT>i = <NUM_LIT:0><EOL>if environ is None:<EOL><INDENT>environ = os.environ<EOL><DEDENT>while True:<EOL><INDENT>m = ENV_VAR_REGEX.search(text, i)<EOL>if not m:<EOL><INDENT>break<EOL><DEDENT>i, j = m.span(<NUM_LIT:0>)<EOL>name = m.group(<NUM_LIT:1>)<EOL>if name.startswith('<STR_LIT:{>') and name.endswith('<STR_LIT:}>'):<EOL><INDENT>name = name[<NUM_LIT:1>:-<NUM_LIT:1>]<EOL><DEDENT>if name in environ:<EOL><INDENT>tail = text[j:]<EOL>text = text[:i] + environ[name]<EOL>i = len(text)<EOL>text += tail<EOL><DEDENT>else:<EOL><INDENT>i = j<EOL><DEDENT><DEDENT>return text<EOL>
Expand shell variables of form $var and ${var}.

    Unknown variables are left unchanged.

    Args:
        text (str): String to expand.
        environ (dict): Environ dict to use for expansions, defaults to
            os.environ.

    Returns:
        The expanded string.