0

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:

/parent/codeandsuch

/parent/codeandsuch_build

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'
0

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"

use:

DIR="${DIR}_build"

The whole thing becomes:

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

Alternatively:

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.