How should the "CDPATH" command be written in the .bashrc file?

I have a folder with deep folders (XAMPP) with which I would like to cd enter.

I run this in the terminal: CDPATH=/Applications/XAMPP/xamppfiles/htdocs/ And it works!

Therefore, if I want this to be permanent, I have to add the same line to the .bashrc . But adding the same line to my .bashrc does not work.

My .bashrc file contains:

 [ -n "$PS1" ] && source ~/.bash_profile CDPATH=/Applications/XAMPP/xamppfiles/htdocs/ 

What should the line in the .bashrc file look like? Are mines wrong? I tried putting export in front of CDPATH as well as $CDPATH:${HOME}/Applications/XAMPP/xamppfiles/htdocs , but it does not work.

+4
source share
2 answers

First, remember that CDPATH is considered first, so you won’t be able to easily switch to a local directory if another directory contains a directory with the same name. You will probably add an empty path in front by writing CDPATH=:/Application/...

You do not need to use export , since this applies only to your shell, and not to the commands executed by your shell. The line, as you wrote it, should be good.

Remember that depending on how you start it, bash will read ~/.bashrc or ~/.bash_profile . Add an echo line for debugging which file is being evaluated in your context.

+5
source

If you want to directly navigate to htdocs using cd htdocs , you must enter:

 export CDPATH=:/Applications/XAMPP/xamppfiles 

to your $HOME/.profile (and open a new Terminal.app window - or source $HOME/.profile )

after that

 cd htdocs 

will cd to /Applications/XAMPP/xamppfiles/htdocs

you can also make a special alias for it, for example:

 alias xcd="cd /Applications/XAMPP/xamppfiles/htdocs" 
+1
source

Source: https://habr.com/ru/post/1483918/


All Articles