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'

1 Answer 1

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"'
1
  • Thanks, appreciate it. The alternative also is much more elegant than what I was trying Commented Jan 31, 2018 at 15:47

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.