Reputation: 110163
I am trying to do the following in bash to modify my .vimrc
:
# *VIM,TMUX-related*
if [(which vim) = '/usr/local/bin/vim'] then
VIM="/usr/local/bin/vim"
else
VIM="/usr/bin/vim"
fi
export EDITOR="$VIM"
What would be the proper syntax to do this conditional?
Upvotes: 0
Views: 278
Reputation: 1110
[["$(which vim)" = "/usr/local/bin/vim"]] && export EDITOR="/usr/local/bin/vim"
will do the trick if you insist on using conditional statement to make sure that vim path exists.
Upvotes: 0
Reputation: 1650
Would it also work for you to directly assign the output of which vim
? This seems to be the endresult of this snippet:
export EDITOR="$(which vim)"
Upvotes: 3
Reputation: 781004
The first line should be:
if [ "$(which vim)" = '/usr/local/bin/vim' ] then
Spaces are needed around [
and ]
, and you need to use $(...)
to substitute the output of a command into the command line. You should also put it in quotes in case it returns an empty string or a string containing whitespace.
Upvotes: 2