def format_commands(settings):
    """ format string commands

    Replace special characters ["$CR", "$LF", "$ACK", "$ENQ"]
    in settings['cmd', 'ack', 'enq'].

    args:
        settings           dict() of settings

    return:
        modified settings
    """
    for key in ['cmd', 'ack', 'enq']:
        if key in settings:
            value = settings[key]
            if isinstance(value, str):
                # string replacements
                for placeholder, replacement in [("$CR", "\x0D"),
                                                 ("$LF", "\x0A"),
                                                 ("$ACK", "\x06"),
                                                 ("$ENQ", "\x05")]:
                    if placeholder in value:
                        value = value.replace(placeholder, replacement)
                settings[key] = value
    return settings