Bash – What does backslash dot mean as a command

bash

A software I installed inserted a line in my profile that reads:

[ -s "$SOME_FILE" ] && \. "$SOME_FILE"

I know dot . is synonymous with source, so I suspect this is just sourcing the file, but I have never seen \. before; does it do something else?

Edit, regarding DVs: searching for "backslash dot" leads to questions regarding ./ when calling executable files, and man source leads to a manpage where \. does not appear. I don't know what else to try, hence the question.

Edit 2: see related questions

Best Answer

A backslash outside of quotes means “interpret the next character literally during parsing”. Since . is an ordinary character for the parser, \. is parsed in the same way as ., and invokes the builtin . (of which source is a synonym in bash).

There is one case where it could make a difference in this context. If a user has defined an alias called . earlier in .profile, and .profile is being read in a shell that expands aliases (which bash only does by default when it's invoked interactively), then . would trigger the alias, but \. would still trigger the builtin, because the shell doesn't try alias expansion on words that were quoted in any way.

I suspect that . was changed to \. because a user complained after they'd made an alias for ..

Note that \. would invoke a function called .. Presumably users who write functions are more knowledgeable than users who write aliases and would know that redefining a standard command in .profile is a bad idea if you're going to include code from third parties. But if you wanted to bypass both aliases and functions, you could write command .. The author of this snippet didn't do this either because they cared about antique shells that didn't have the command builtin, or more likely because they weren't aware of it.

By the way, defining any alias in .profile is a bad idea because .profile is a session initialization script, not a shell initialization script. Aliases for bash belong in .bashrc.

Related Question