1

In my bash profile I create a variable called SCRIPTS to use in the future and I add it to my PATH variable like this:

SCRIPTS="~/Code/Scripts"
PATH="${PATH}:${SCRIPTS}"
export PATH
export SCRIPTS

I have a file in the directory ~/Code/Scripts called CA.sh, if I type

vim ~/Code/Scripts/CA.sh

I can open that file but and edit it through vim, but if I type

vim $SCRIPTS/CA.sh 

or

vim ${SCRIPTS}/CA.sh

it opens an empty vim window so it looks like a new file and at the very bottom, it says "~/Code/Scripts/CA.sh" [New DIRECTORY] and I can not write to file because vim says E212: Can't open file for writing. How do I make it so that vim opens the existing file I want it to and why is using a variable from bash making vim act this way?

  • 1
    The `~` is interpreted by the shell as your home directory when you use it at the prompt. When it's used as part of a shell variable value, it's not interpreted. It's just a character. Use `SCRIPTS="$HOME/Code/Scripts/CA.sh"` instead. – lurker Aug 08 '18 at 22:17

0 Answers0