def append_variable(var, val):
    """Return a valid bash string to append a value to a variable. """
    ans = 'if [[ ":$%s:" != *":%s:"* ]]; then\n' % (var, val)
    ans += '    export %s=%s:$%s\n' % (var, val, var)
    return ans + 'fi\n'