Why are backslashes included in this shell script?

Backslash will suppress alias expansion, ie it executes the original command and makes sure that alias version does not run. Scripts can unknowingly run with alias expansion when the system has set shopt -s expand_aliases (BASH only) or if it is executed using source.

./conda.sh          # usually no alias expansion (unless `shopt -s expand_aliases` in BASH)
source ./conda.sh   # alias expansion
. ./conda.sh        # alias expansion

Some sysadmins like to put backslash in everything as a preventive measure against side-effects of aliases, just in case it was aliased unintentionally somewhere else and the alias gets expanded as explained previously. For example, if the system has set this alias dirname='dirname -z' somewhere and the condition allows the alias to be expanded, then a script that tries to call dirname will unfortunately call dirname -z instead, which was not the script intended.

If there's certainty that such alias do not exist, we can remove all the backslash and it should work fine.

Alternatively, one can use command instead of backslash version to suppress alias. Thus, instead of \dirname, one can use command dirname, which might look more readable. (For built-in commands like cd, one should use builtin instead). I prefer this instead, as it also bypasses function with same name as well as any aliases.


If conda.sh is a file meant to be sourced, then the backslashes are for bypassing aliases. Bash typically disables alias expansion for script execution, but for sourced files, which may run in interactive shells, that's not the case. So just dirname may run an alias named dirname, but \dirname will skip alias expansion and run a function or command named dirname. (Not just backslashes, though, any quoting will do.)