Animal Farm
Animal Farm

Reputation: 27

What is exactly ".\" in zsh commands

When I was installing NVM through Homebrew, I found it. The backslash seems to be escaping the dot. Whey are they exactly doing before the shell script?

export NVM_DIR="$HOME/.nvm"
  [ -s "/opt/homebrew/opt/nvm/nvm.sh" ] && \. "/opt/homebrew/opt/nvm/nvm.sh"  # This loads nvm
  [ -s "/opt/homebrew/opt/nvm/etc/bash_completion.d/nvm" ] && \. "/opt/homebrew/opt/nvm/etc/bash_completion.d/nvm"  # This loads nvm bash_completion

Upvotes: 0

Views: 76

Answers (1)

Jens
Jens

Reputation: 72697

Could be a line ending quirk, that interestingly does not change semantics. I.e. the original code could have been

export NVM_DIR="$HOME/.nvm"
[ -s "/opt/homebrew/opt/nvm/nvm.sh" ] && \
. "/opt/homebrew/opt/nvm/nvm.sh"  # This loads nvm
[ -s "/opt/homebrew/opt/nvm/etc/bash_completion.d/nvm" ] && \
. "/opt/homebrew/opt/nvm/etc/bash_completion.d/nvm"  # Loads nvm bash_completion

and then the newlines got removed. Quoting the dot command wit \. has no effect other than suppressing alias-substitution. See also my answer to Why start a shell command with a backslash?

The code checks whether the files are non-empty and if so, sources them.

Upvotes: 1

Related Questions