1

I'm probably doing something obvious wrong here.
In $HOME/.bash_profile I've added (note the space in the path):

export PROJ="~/Documents/project livefeed"

After that I get:

➜  ~ cd $PROJ                  
cd: no such file or directory: ~/Documents/project livefeed

Any idea what's wrong? I've attempted adding a backslash before the space between the quotes, but this didn't help either.

The folder exists:

➜  ~ cd ~/Documents/project\ livefeed
➜  project livefeed 

Also I applied:

➜  ~ source $HOME/.bash_profile
1

~ doesn't get expanded inside "". To make it work, use

export PROJ=~/"Documents/project livefeed"
  • I've tried this, but it also didn't work. – Kim Gysen Mar 16 '18 at 19:08
  • 1
    Did you try it as: cd "$PROJ"? – Jeff Schaller Mar 19 '18 at 0:20
0

This is a charming feature (or woeful wart) of POSIX shells. You'll need to always quote the $PROJ variable (so cd "$PROG" everywhere and time you interpolate that variable) or instead use some other shell such as ZSH that does not do the POSIX word split thing.

% mkdir "a dir"
% dir="a dir"
% cd $dir
% pwd
/Users/jhqdoe/tmp/a dir
% cd ..
% bash
bash-3.2$ dir="a dir"
bash-3.2$ cd $dir
bash: cd: a: No such file or directory
bash-3.2$ exit
exit
% 
  • Well it's a coincidence, I use zsh, but it doesn't work. Can you post the solution in terms of what I have? I've tried adding quotes cd "$PROJ"but this isn't working either. – Kim Gysen Mar 15 '18 at 19:42
  • 1
    I suspect the quoted ~ is the problem here. – Jeff Schaller Mar 15 '18 at 19:44
  • @JeffSchaller When changing to the actual /Users/username directory it isn't actually working either. I guess that I miss the complete solution here, probably missing something obvious. – Kim Gysen Mar 15 '18 at 19:52
  • 1
    Since the error message in the question includes the space, this is clearly not the issue. – Michael Homer Mar 15 '18 at 21:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.