I've been using cmake and creating a build folder for my cmake code and I want to easily cd to the build directory. I've been naming my build directory in this format:



I've tried the following alias in my bashrc but its not working. Ive copied the name of the current directory to a string, added _build to it and tried to cd but its not working. Any ideas? Thanks

alias cdbuild='DIR=${PWD##*/} || DIR = DIR + "_build"|| echo DIR || cd ../DIR'

1 Answer 1


You can't concatenate strings with + in bash. Also you need to prepend a $ to the variable name to use its value. So, instead of:

DIR = DIR + "_build"



The whole thing becomes:

alias cdbuild='DIR=${PWD##*/} || DIR="${DIR}_build || echo "$DIR" || cd "../$DIR"'


alias cdbuild='cd "$(pwd)_build"'
  • Thanks, appreciate it. The alternative also is much more elegant than what I was trying
    – saphire121
    Jan 31, 2018 at 15:47

You must log in to answer this question.

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