Search code examples
bash

Why are there backslashes before keywords in this Bash function?


Why are there backslashes before the local and return keywords in this Bash function?

mamba() {
    \local cmd="${1-__missing__}"
    case "$cmd" in
        activate|deactivate)
            __conda_activate "$@"
            ;;
        install|update|upgrade|remove|uninstall)
            __mamba_exe "$@" || \return
            __conda_reactivate
            ;;
        *)
            __mamba_exe "$@"
            ;;
    esac
}

Solution

  • To not use aliases. Or more precisely to provide a command name that contains a backslash in the shell code, but represents the command name as local or return as the word how the interpreter handles it.

    This is a marker how the shell has to resolve the command for that name and quotes the the following character which has no other special meaning but for the newline character.

    So in your case it is rudimentary equivalent to local or return by the common understanding.

    Cf. Escape Character (Backslash), Command Search and Execution