Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

I have a directory deep in folders (XAMPP) I'd like to cd into directly into.

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

So if I want this to be permanent, I must add this same line to the .bashrc file. But adding the same line to my .bashrc file doesn't work.

My .bashrc file contains:

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

How should the line look like in the .bashrc file? Is mines wrong? I've tried putting export in front of CDPATH and also $CDPATH:${HOME}/Applications/XAMPP/xamppfiles/htdocs but neither works.

like image 902
Henry Zhu Avatar asked Mar 24 '23 18:03

Henry Zhu


1 Answers

First be aware that CDPATH is considered first, hence you will not be able to easily change to a local directory if the other directory contains a directory with the same name. You will probably add an empty path in front, writing CDPATH=:/Application/....

You should not need the export as this one is only relevant for you shell, not for commands run by your shell. The line as you wrote it should be fine.

Be aware that, depending how you start it, bash will read ~/.bashrc or ~/.bash_profile. Add an echo line in both to debug which file is evaluated in your context.

like image 160
michas Avatar answered Apr 05 '23 21:04

michas