I've been relying on this hack for jumping around in the file system for a couple of years before finding out today that I can do the same thing using native Bash by activating the option cdable_vars.

The only thing I miss is tab completion. If I put this in my .bashrc or .bash_profile:

shopt -s cdable_vars
export mydir="$HOME/my/nested/directory"

Tab completion isn't expanding mydir when I try to cd into it from the prompt. Is there a way to activate this behavior in Bash?

1 Answer 1


To activate this completion you need the bash-completion package.

If the package is installed (often by default) just add these lines in your .bashrc

if [ -f /etc/bash_completion ]; then
    . /etc/bash_completion

If not: https://repology.org/project/bash-completion/versions

  • Weird, I've always used completion everywhere without having this installed. Anyway now it does what I want, thanks a lot!
    – mrzool
    Nov 24, 2015 at 13:15
  • The tab completion works with the cd command, though I use the path often with the mv command, which does not work. I wonder, if it could work as well.
    – xralf
    Jun 22, 2017 at 22:04
  • 1
    @djangoliv Your link is broken
    – Max Coplan
    Feb 11, 2019 at 18:39

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .