mapkyc3000
mapkyc3000

Reputation: 39

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!

Upvotes: 3

Views: 2103

Answers (1)

Abhijit Pritam Dutta
Abhijit Pritam Dutta

Reputation: 5591

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"

Upvotes: 1

Related Questions