How do I set up a bash alias for a common working folder?

62 Views Asked by At

I want to set up a bash alias or function (let's call it "myfolder") to a common working directory (let's call it ~/some/deep/working/folder) and I want to be able to call it like this:

cd myfolder/bob to access the child folder "bob".

If I use alias myfolder='~/some/deep/working/folder', I can use cd myfolder, but I can't use cd myfolder/bob.

How do I get the alias expansion to happen first, and then have any other text be added onto the command before executing the command?

1

There are 1 best solutions below

0
On BEST ANSWER

Two workarounds:

Add this to your .bashrc:

CDPATH="$CDPATH:$HOME/some/deep/working"

then you can use

cd folder/bob

from everywhere.


Use a variable:

myfolder="$HOME/some/deep/working/folder"
cd "$myfolder/bob"