Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

cd $PATH : No such file or directory

I am running .bash on macOS (Sierra). I am setting up the following $AVGPATH environment variable:

mpdelps-MacBook-Pro:~ mdelp$ pwd
/Users/mdelp
mpdelps-MacBook-Pro:~ mdelp$ AVGPATH="/Users/mdelp/Google\ Drive/Cloud\ Downloads/Avantgardist/ADGM\ Reporting/dev"
mpdelps-MacBook-Pro:~ mdelp$ echo $AVGPATH
/Users/mdelp/Google\ Drive/Cloud\ Downloads/Avantgardist/ADGM\ Reporting/dev
mpdelps-MacBook-Pro:dev mdelp$

Now, when I try to run a simple 'cd' command using that variable, I am getting the following error from Terminal:

mpdelps-MacBook-Pro:~ mdelp$ cd $AVGPATH
-bash: cd: /Users/mdelp/Google\: No such file or directory
mpdelps-MacBook-Pro:dev mdelp$

However, when I simply copy and paste the value of the $AVGPATH variable, the command works:

mpdelps-MacBook-Pro:~ mdelp$ cd /Users/mdelp/Google\ Drive/Cloud\ Downloads/Avantgardist/ADGM\ Reporting/dev
mpdelps-MacBook-Pro:dev mdelp$ pwd
/Users/mdelp/Google Drive/Cloud Downloads/Avantgardist/ADGM Reporting/dev
mpdelps-MacBook-Pro:dev mdelp$

I am scratching my head here. Could someone explain how the shell is presenting the value of the $AVGPATH variable to the 'cd' command?

Thank you!

like image 561
mapkyc3000 Avatar asked Jan 23 '26 21:01

mapkyc3000


1 Answers

Please notice there are 3 space in your path \ Drive, \ Downloads/ and \ Reporting/. To avoid that side effect you always need to put the variable with double quote like below:-

cd "$AVGPATH"
like image 59
Abhijit Pritam Dutta Avatar answered Jan 26 '26 13:01

Abhijit Pritam Dutta