Search code examples
terminalzshoh-my-zshzshrc

When I open my terminal, I receive the following message -> /Users/pankajkumar/.zshrc:[:9: ']' expected


It seems that whenever I open my terminal in Mac M1, I get this error message. I have attached a screenshot of the terminal, as well as a .zshrc file. If anyone knows the solution, please let me know.

👇 The terminal displays this information 👇

/Users/pankajkumar/.zshrc:[:9: ']' expected
pankajkumar@Pankajs-MacBook-Pro ~ %

👇 Data inside .zshrc file 👇

local brew_opt_path="/opt/homebrew/opt"
local nvm_path="$HOME/.nvm"

export PATH="${brew_path}:${PATH}"
export NVM_DIR="${nvm_path}"

[ -s "${brew_opt_path}/nvm/nvm.sh" ] && . "${brew_opt_path}/nvm/nvm.sh" #This load nvm

[ -s "${brew_opt_path}/nvm/etc/bash_completion.d/nvm"] && . "${brew_opt_path}/nvm/etc/bash_completion.d/nvm" #This loads nvm bash_completion

export PATH="/opt/homebrew/opt/[email protected]/bin:$PATH" export PATH="/opt/homebrew/opt/[email protected]/sbin:$PATH"


Solution

  • Spaces matter when dealing with the brackets:

    [ -s "${brew_opt_path}/nvm/etc/bash_completion.d/nvm"] && . "${brew_opt_path}/nvm/etc/bash_completion.d/nvm" #This loads nvm bash_completion
    

    This must be like so:

    [ -s "${brew_opt_path}/nvm/etc/bash_completion.d/nvm" ] && . "${brew_opt_path}/nvm/etc/bash_completion.d/nvm" #This loads nvm bash_completion
    

    Notice the space between nvm" and ].